Say I have a class called Foo. Foo doesn't have a default constructor. It has a constructor Foo(int x, float y).
Bar is a container class. It contains a vector that contains instances of Foo.
Bar::Bar(int numberOfFoos, int x, float y) {
foovector.resize (numberOfFoos);
for(int i = 0; i < numberOfFoos; i++) {
**read below**
}
at this point, I want to call the constructor of Foo and pass to it the parameters int x and float y. The constructor of Foo does different things depending on the value of x and y.
Let's say Foo had a default constructor, what exactly does the resize vector function do? Does it simply resize the vector without calling the default constructor? In other words, is space reserved for n elements of type Foo but they aren't initialized to anything??
What if it doesn't have one, like in this case?
in the for loop I want to initialize each Foo element in this way:
foovector[i].Foo(int x, float y);
but I can't call the constructor using the dot access operator in this way. I don't even know at this point if the constructor has already been called by the resize function or not.
Question is, how can I do it?
Another related question about vectors of classes:
In Foo there is a vector that holds floats. the float x parameter is the number of floats that it should hold. Foo's constructor has a line
arrayofFloats.resize (x);
But that means that the computer doesn't know beforehand the size of Foo. And each foo can have different size. Wouldn't it cause problems for a vector of Foo's? How can a vector of specific size be declared if each Foo can have different size?
Sorry for bad english, I hope it has been clear enough.
Thank you.