constructor problem

Kris Thielemans kris.thielemans@csc.mrc.ac.uk
Mon Feb 21 04:53:00 GMT 2000


Dear Leonhard,

This is just C++. In your first constructor, you are just constructing a
local object with the 1st constructor. You are not 'calling the constructor
function on the same object'. Constructors are not ordinary functions.

To do something like you want, you would have to have a 3rd function

class A
{
  A() { f(); }
  A(int a) { f(); /*do something with a*/ };
  void f() { /*blabla*/ }
};

There are some restrictions on which functions you can call from within
constructors though (notably: do not call virtual functions).

Kris


> -----Original Message-----
> From: cygwin-owner@sourceware.cygnus.com
> [ mailto:cygwin-owner@sourceware.cygnus.com]On Behalf Of Leonhard
> Grünschloß
> Sent: 21 February 2000 13:44
> To: cygwin@sourceware.cygnus.com
> Subject: constructor problem
>
>
> I don't know if that's Cygwin specific, but that's my problem:
> If I call a second constructor from the first constructor it is
> called, but
> the (private) variables it changed aren't changed when it returns to the
> first constructor. Why not? How else can I call the constructor
> so that its
> actions aren't "undone"?
> --OyL


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com



More information about the Cygwin mailing list