Re: Inline destructors and construtors
On Jan 29, 1:04 pm, "abhijith....@gmail.com"
<abhijith....@gmail.com> wrote:
What is the use of declaring inline destructors ?
destructors gets called automatically which means for every
object when it is about to get out of scope OR when we call
delete etc. and hence it should be a function.
It is a function. The same reasons for inlining it apply that
apply for any function.
In practice, the only time I inline a destructor is in an
interface. Or when the profiler says I should.
Also why we need inline constructors ?
For the same reason we need any inline function. Current
optimization technology isn't sufficient (at least in most
compilers).
In the case of special member functions (constructors,
destructors and the assignment operator), another reason for
inlining them in the case of interfaces may be to avoid needing
an implementation file. A call-back interface, for example,
will usually not have any implementation. It still requires a
user defined destructor, however, since the compiler provided
one won't be virtual. And in some cases, you might want to make
the constructor or the destructor protected. In such cases, it
seems silly to have to create a source file just for the empty
destructor, and I'll write:
class MyInterface
{
public:
virtual MyInterface() {}
// ...
} ;
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34