Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <1F5F2CE7819FD3119835006008F5CDF4247D46@zugitsmxs01.zug.fantastic.com> From: Marco Welti To: =?iso-8859-1?Q?=27Leonhard_Gr=FCnschlo=DF=27?= , cygwin AT sourceware DOT cygnus DOT com Subject: RE: constructor problem Date: Mon, 21 Feb 2000 13:56:07 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01BF7C6B.082CFB36" ------_=_NextPart_001_01BF7C6B.082CFB36 Content-Type: text/plain; charset="iso-8859-1" > 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 AT sourceware DOT cygnus DOT com > ------_=_NextPart_001_01BF7C6B.082CFB36 Content-Type: text/html; charset="iso-8859-1" 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 AT sourceware DOT cygnus DOT com
>

------_=_NextPart_001_01BF7C6B.082CFB36--