Hello!
I'm having some problems with constructor initialization,mainly because I have object members and vectors within classes.
I have a class Factory in which i have 2 object members(base and dumpster),a vector of Floors and a set of Robots.
Each Floor has a size(lin,col) and a member object Cell which represents the cells in a given floor
I want to be able to initialize the Factory upon it's creation with the parameters on the constructor below.
The problem is: I want to construct the Factory with a certain number of floors(say 2 floors).How do I do that in the constructor?
I also want to initialize each floor with cells(each cell occupies a 1x2 space upon the construction of the Factory,based on the linxcol of the floor.How do I do that?My current Factory initialization is declared on main like this: Factory f(floors(lin,col,cell(x,y,residue(quant))),robots,dumpster(lposxx,lposyy),base(bposxx,bposyy));
I think this is only initializing one floor with one cell,but I want it to initialize it as described above!
Here are the classes:

class Fabrica
{
private:
	int trackCurrentFloor=0;
	vector<Floor> floors;
	set<Robot> robots;
	Dumpster dumpster;
	Base base;

public:
	Factory(vector<Floor> floors,set<Robot> robots,Dumpster dumpster,Base base);
...
}

class Residue
{
private:
	int quantity=0;
...
}

class [B]Floor[/B]
{
private:
	int lin;
	int col;
	Cell cell;
}

class Cell
{
private:
	vector<Residue> residues;
	int xx;
	int yy;
}

class [B]Dumpster[/B]
{
private:
	int x;
	int y;
}

class [B]Base[/B]
{
private:
	int x;
	int y;

}

class [B]Robot[/B]
{
private:
	int x;
	int y;
...
 }

void [B]main[/B]()
{

...

Factory f(floors(lin,col,cell(x,y,residue(quant))),robots,dumpster(lposxx,lposyy),base(bposxx,bposyy));

...
}

Thanks in advance for the reply!

You haven't posted your constructor definition?

So, let's say I ask the user to input the number of floors that will be stored in a nfloor variable, how would the constructor and initialization list look like if i use that variable to determine the size of the vector?Also,how would the initialization list look like if I wanted to construct the factory floor with a given number of cells?

IMO you should create those objects separately and then add them to the vectors and sets of the factory class. Factory, in your case (and very misleadingly), looks like a collection of all other types and I don't think you should create these objects in the Factory, rather, just create a Floor and it to the vector in Factory. So you probably first need to figure out the ctors for all the other classes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.