[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [ProgSoc] dumbass c++ q



> > is this legit? i.e. can I call a constructor from within another
> > constructor?
> >
> 
> Yep. You can also explicitly call constructors from base classes in two
> ways:

the only thing is, I'm not calling the constructor of a base class, I'm
calling a different constructor within the same class.  e.g. 

struct agg { int x; int y;};
foo::foo(struct agg c);
{
   foo(c.x, c.y);
}
foo::foo(int a, int b) 
{
   //some code here
}

from what I've just tried it doesn't seem to work; is there an easier way
of doing this than creating another function

foo::init(int a, int b)

then calling that from the actual constructors like

foo::foo(int a, int b) { init(a,b);}
foo::foo(struct agg c) { init(c.x, c.y);}

chow

vik

<http://www.progsoc.org/~vik>
PGP: <http://www.progsoc.org/~vik/pgp.txt>

"I think it would be a good idea." Ghandi, on Western Civilisation


-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.