Mail Archives: djgpp/1998/02/09/22:46:20
Geoffrey French wrote:
> int main()
> {
> TC x, *y;
>
> x = TC(1);
> y = new TC(1);
> }
>
> I find that upon calling the constructor TC(long i) in the line 'x =
> TC(1)' not only is the constructor called, but the destructor is
> called straight afterwards (!), thus deleteing the reserved memory for
> the variable a. However, in the line 'y = new TC(1)' only the
> constructor is called. It seems that whenever you say 'c =
> TClass(...)' the TClass destructor is called as well as the
> constructor.
by the time
x = TC(1);
has been executed, x has already been initialized using the default
constructor. you can use:
TC x(1);
to use the alternate constructor.
-- Sinan
- Raw text -