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

c++constructordestructor

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);
}

Best Solution

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.