Calling constructor

From: Sylvain (sylvain.boucher_at_aitb.org)
Date: 02/12/04


Date: Thu, 12 Feb 2004 20:00:24 +0100

Let's say I have the following code where a class 'pipo' has 8 instances
of foo:

class foo
{
foo ( const char * _name):
   name = _name
     {

     }
private:
    const char * name;
};

class pipo
{
foo *mf[8];
pipo()
{
   for (unsigned int i = 0 ; i < 8; ++i)
        {
        ostringstream ost;
        ost << "MY_FOO_" << i;
        string name = ost.str();
        mf[i] = new foo (name.c_str());
        }
}
};

Is it mandatory to do in such a way: using array of pointers on foo. Or
may I do it by using plain array of instances of foo?
In this case, I have no clue how to process to call the constructor with
the correct C like string as defined in the exemple...
Do you have any ideas how to proceed?

Something like this?

class pipo
{
foo mf[8];
pipo ():
????
{

}
};

Regards

Sylvain



Relevant Pages