composition: initializing array of objects

Hi everybody, my name is Ale and this is my first topic here.

I'm getting in trouble with the initialization of an array of objects in a relation of "has a" between classes.

This is an explanation:

class MyType {
public:
MyType(); // default constructor
MyType( string ); // what does: MyType( string _s){s = _s; i = 0; b = 0; }
// others methods
private:
string s;
int i;
bool b;

};

class HostClass {
public:
// default constructor
HostClass() : _i(5) // {
i = 0;
s = " ";
/* each array's element should be initialized with MyType default constructor, right? */
}

// constructor with parameters
HostClass(string one, string two, string three, string four, string five)
: _i(5)
/* here i need to initialize each array's element with no default constructor of MyType class and to assign a _i dimension to the array */
/* i've tried lots of ways but i think they do not really initialize the array because when i print it, appears to be empty. I didn't find any info about the initialization of an array of objects in a composition */
{
i = 0;
s = " ";
}

private:
int i;
const int _i;
string s;
MyType arr[]; // should have a dimension equal to _i
};


How would u resolve it?
Thank u all for helping me

Ale
Topic archived. No new replies allowed.