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/


Relevant Pages

  • accessing a private member (illegally)
    ... Let's say I've got a class defined in a header file. ... int bar; ... Now lets say I have a function that needs to access the private variable ... I don't want to change anything inside the class foo ...
    (comp.lang.cpp)
  • Re: self and private setter
    ... about whether an explicit receiver may be used. ... with a receiver, and unless it is necessary to use private (e.g., ... def call_prot ...
    (comp.lang.ruby)
  • Re: accessing a private member (illegally)
    ... > Now lets say I have a function that needs to access the private variable ... > lets say I have a constraint where I cannot modify the header file. ... I don't want to change anything inside the class foo ...
    (comp.lang.cpp)
  • Re: from Python to Ruby in 10 seconds
    ... On Sun, 12 Mar 2006, Bill Guindon wrote: ... loosely for private references. ... For example, "class Foo; ... Ruby Power and Light, LLC ...
    (comp.lang.ruby)
  • Re: self and private setter
    ... about whether an explicit receiver may be used. ... with a receiver, and unless it is necessary to use private (e.g., ... def call_prot ...
    (comp.lang.ruby)