Re: interface programming
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Mon, 3 Apr 2006 19:48:17 -0700
dummy#1 wrote:
Hi All,
I have a question.
In C#, I have auto garbage collector so I can freely do:
ICar pGenericCar = carFactory.createCar( toyotaEnum );
Without worrying about memory leaks.
in C++, how can I do the same without memory leaks?
ICar pGenericCar = carFactory.createCar( toyotaEnum ); // who will
delete this heap object since C++ interfaces have no ctor or dtor?
There's no such thing as an interface in C++ - there are classes and
structs, that's all. Unless you're talking about managed C++ that is, in
which case you also have garbage collection so there's nothing to worry
about.
For native C++, there are two common patterns for interfaces:
1. COM style - AddRef/Release used to manage object lifetime.
2. Virtual destructor - object holder manages lifetime.
Which kind of "interface" are you working with?
-cd
.
- Prev by Date: Re: interface programming
- Next by Date: Re: Is there analog of std::mem_fun_t, but for data members?
- Previous by thread: Re: interface programming
- Next by thread: Re: interface programming
- Index(es):
Relevant Pages
|