Mail Archives: cygwin/2000/02/21/07:49:44
------_=_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>> 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> A(int a) : A(a, 5) {}</FONT>
<BR><FONT SIZE=2> A(int a, int b) : a_(a), b_(b) {}</FONT>
</P>
<P><FONT SIZE=2> private:</FONT>
<BR><FONT SIZE=2> int a_;</FONT>
<BR><FONT SIZE=2> int b_;</FONT>
<BR><FONT SIZE=2>};</FONT>
</P>
<P><FONT SIZE=2>main()</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> A a(1)</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>
<P><FONT SIZE=2>> If I call a second constructor from the first constructor it </FONT>
<BR><FONT SIZE=2>> 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>> but </FONT>
<BR><FONT SIZE=2>> the (private) variables it changed aren't changed when it </FONT>
<BR><FONT SIZE=2>> returns to the </FONT>
<BR><FONT SIZE=2>> first constructor. </FONT>
</P>
<P><FONT SIZE=2>> 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> </FONT>
<BR><FONT SIZE=2>> How else can I call the </FONT>
<BR><FONT SIZE=2>> constructor so that its </FONT>
<BR><FONT SIZE=2>> actions aren't "undone"?</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>> ______________________________________________________</FONT>
<BR><FONT SIZE=2>> Get Your Private, Free Email at <A HREF="http://www.hotmail.com" TARGET="_blank">http://www.hotmail.com</A></FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> --</FONT>
<BR><FONT SIZE=2>> Want to unsubscribe from this list?</FONT>
<BR><FONT SIZE=2>> Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com</FONT>
<BR><FONT SIZE=2>> </FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01BF7C6B.082CFB36--
- Raw text -