delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/02/21/07:49:44

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
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 <marco DOT welti AT fantastic DOT com>
To: =?iso-8859-1?Q?=27Leonhard_Gr=FCnschlo=DF=27?=
<gruenschloss AT hotmail DOT com>,
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)

------_=_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"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2650.12">
<TITLE>RE: constructor problem</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>&gt; I don't know if that's Cygwin specific, but that's my problem:</FONT>
</P>

<P><FONT SIZE=2>This is not a cygwin problem, but it is not possible with c++ !!</FONT>
</P>

<P><FONT SIZE=2>class A</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; A(int a) : A(a, 5) {}</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; A(int a, int b) : a_(a), b_(b) {}</FONT>
</P>

<P><FONT SIZE=2>&nbsp;&nbsp; private:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp; int a_;</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp; int b_;</FONT>
<BR><FONT SIZE=2>};</FONT>
</P>

<P><FONT SIZE=2>main()</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp; A a(1)</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>

<P><FONT SIZE=2>&gt; If I call a second constructor from the first constructor it </FONT>
<BR><FONT SIZE=2>&gt; is called, </FONT>
</P>

<P><FONT SIZE=2>Yep, second constructor gets called, but probably not the way you think ;-)</FONT>
</P>

<P><FONT SIZE=2>&gt; but </FONT>
<BR><FONT SIZE=2>&gt; the (private) variables it changed aren't changed when it </FONT>
<BR><FONT SIZE=2>&gt; returns to the </FONT>
<BR><FONT SIZE=2>&gt; first constructor. </FONT>
</P>

<P><FONT SIZE=2>&gt; Why not? </FONT>
</P>

<P><FONT SIZE=2>Because you are ceating a second, local, object which is destroyed as soon as</FONT>
<BR><FONT SIZE=2>the (second) constructor finishes.</FONT>
<BR><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>&gt; How else can I call the </FONT>
<BR><FONT SIZE=2>&gt; constructor so that its </FONT>
<BR><FONT SIZE=2>&gt; actions aren't &quot;undone&quot;?</FONT>
</P>

<P><FONT SIZE=2>You can't (at least in c++) ;-(</FONT>
</P>

<P><FONT SIZE=2>regards </FONT>
<BR><FONT SIZE=2>Marco</FONT>
<BR><FONT SIZE=2>&gt; ______________________________________________________</FONT>
<BR><FONT SIZE=2>&gt; Get Your Private, Free Email at <A HREF="http://www.hotmail.com" TARGET="_blank">http://www.hotmail.com</A></FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; --</FONT>
<BR><FONT SIZE=2>&gt; Want to unsubscribe from this list?</FONT>
<BR><FONT SIZE=2>&gt; Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01BF7C6B.082CFB36--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019