In C++ can constructor and destructor be inline functions?

popopome picture popopome · Aug 22, 2008 · Viewed 75.7k times · Source

VC++ makes functions which are implemented within the class declaration inline functions.

If I declare a class Foo as follows, then are the CONSTRUCTOR and DESTRUCTOR inline functions?

class Foo 
{
    int* p;
public:
    Foo() { p = new char[0x00100000]; }
    ~Foo() { delete [] p; }
};

{
    Foo f;
    (f);
}

Answer

user2189331 picture user2189331 · Aug 22, 2008

Defining the body of the constructor INSIDE the class has the same effect of placing the function OUTSIDE the class with the "inline" keyword.

In both cases it's a hint to the compiler. An "inline" function doesn't necessarily mean the function will be inlined. That depends on the complexity of the function and other rules.