constructor problem

Marco Welti marco.welti@fantastic.com
Mon Feb 21 04:57:00 GMT 2000


Title: RE: constructor problem





> I don't know if that's Cygwin specific, but that's my problem:


This is not a cygwin problem, but it is not possible with c++ !!


class A
{
    A(int a) : A(a, 5) {}
    A(int a, int b) : a_(a), b_(b) {}


   private:
     int a_;
     int b_;
};


main()
{
   A a(1)
}


> If I call a second constructor from the first constructor it 
> is called, 


Yep, second constructor gets called, but probably not the way you think ;-)


> but 
> the (private) variables it changed aren't changed when it 
> returns to the 
> first constructor. 


> Why not? 


Because you are ceating a second, local, object which is destroyed as soon as
the (second) constructor finishes.
 
> How else can I call the 
> constructor so that its 
> actions aren't "undone"?


You can't (at least in c++) ;-(


regards 
Marco
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
> 
> 
> --
> Want to unsubscribe from this list?
> Send a message to cygwin-unsubscribe@sourceware.cygnus.com
> 






More information about the Cygwin mailing list