vector <T> construction

Hello everyone!

I was wondering, suppose I created a class foo as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class widget
{
    public:
        int id;
        widget()
        {
            id = -100;
        }
};

class foo
{
    public:
        string name;
        int age;
        vector <vector <widget>> something;
        vector <widget> somethingelse[10];
        foo()
        {
            name = "noname";
            age = 0;
        }
};       


Now, in my program, I create an instance offoo as follows:
1
2
3
4
foo fooey;
vector <vector<widget>> widgety; //Try this to check a default output
cout << fooey.something[0][0].id << endl; //output1
cout << fooey.somethingelse[0][0].id << endl; //output2 


Programs crashes and reports an unprecedented error meesage.

What's the problem:
vector<widget> anotherthing[10] must create a 10-element array of type widget, and each id value of these widgets must be -100;
Why isn't that happening?
I'm confused.

Thanks for any help!
Last edited on
try putting something into your array in order to access it. push_back();
Worked!
Thaks! :)
NP ;)
Topic archived. No new replies allowed.