Why does VS Code give me this error? : non-aggregate type 'list<int>' cannot be initialized with an initializer listgcc

46 views Asked by At

Currently writing a very basic C++ program to practice some data structures. I had no problem implementing a queue function but when it came to initializing a list, VS Code spat back an error I can't seem to resolve.

#include <iostream>
#include <string>
#include <list>
#include <queue>
using namespace std;

void queueDisplay(int a, int b, int c, int d) {
    queue<int> myqueue;
    myqueue.push(a);
    myqueue.push(b);
    myqueue.push(c);
    myqueue.push(d);
    
    cout << "Initial queue: ";
    while(!myqueue.empty()) {
        cout << myqueue.front() << " ";
        myqueue.pop();
    }

    cout << "\n";

}

void listDisplay(list<int> myList) {
    cout << "Initial list: ";
    for(int l : myList) {
        cout << l << " ";
    }
    cout << "\n";
}


int main() {
    int a = 1999;
    int b = 2001;
    int c = 2003;
    int d = 2007; 

    list<int> age = {24, 22, 20, 16};

    queueDisplay(a, b, c, d);
    listDisplay(age);

    return 0;
}

Was expecting the program to list out the contents of 'age'. Not sure if it has something to do with the version of C++ I'm using (clang version 14.0.3) or .json settings.

0

There are 0 answers