Re: Calling constructor

From: Cy Edmunds (cedmunds_at_spamless.rochester.rr.com)
Date: 02/13/04


Date: Fri, 13 Feb 2004 03:28:16 GMT


"Sylvain" <sylvain.boucher@aitb.org> wrote in message
news:402bccbb$0$41749$5fc3050@dreader2.news.tiscali.nl...
> 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

what is this? ITYM name(_name)

> {
>
> }
> private:
> const char * name;
> };

If you are planning to put class instances in a container it is wise to
include a default constructor:

class foo
{
public:
    foo() : name(0) {}
    foo ( const char * _name) : name(_name) {}
private:
    const char * name;
};

Then to make an array:

foo mf[8];
for (int j = 0; j < 8; ++j)
    mf[j] = foo("abc");

-- 
Cy
http://home.rochester.rr.com/cyhome/