Naren wrote:
> "Erik Wikström" <Erik-> wrote in message
> news:jjsNi.10477$...
>> On 2007-10-05 16:51, Naren wrote:
>>> Please tell me which of this is correct.
>>>
>>> class B
>>> {
>>> A a;
>>> public:
>>> B(){a.Doif();}
>>> ~B(){a.Doelse();}
>>> };
>>>
>>> class B
>>> {
>>> A* a;
>>> public:
>>> B():a(new A) {a->Doif();}
>>> ~B(){a->Doelse();delete a;}
>>> };
>>>
>>> Second one will always work.
>>>
>>> Is first one undefined, though I have verified that both works correctly.
>> In what way? I would probably use the first one, but it depends on what
>> A and B are and how I would use them.
>
> Since I am in the destructor, any issues?
No, as in the second version, a is destructed after the destructor of B
is finished, so in it you can work with a to your liking.
Cheers,
Daniel
--
Got two Dear-Daniel-Instant Messages
by MSN, associate ICQ with stress--so
please use good, old E-MAIL!
|