<p>VC++ makes functions which are implemented within the class declaration inline functions.</p>

<p>If I declare a class <code>Foo</code> as follows, then are the CONSTRUCTOR and DESTRUCTOR inline functions?</p>

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

{
    Foo f;
    (f);
}
</code></pre>

[{'answer_id': 21322, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 7, 'selected': True, 'text': "<p>Defining the body of the constructor INSIDE the class has the same effect as placing the function OUTSIDE the class with the &quot;inline&quot; keyword.</p>\n<p>In both cases it's a hint to the compiler. An &quot;inline&quot; function doesn't necessarily mean the function will be inlined. That depends on the complexity of the function and other rules.</p>\n"}, {'answer_id': 21324, 'author': 'Mickey', 'author_id': 1494, 'author_profile': 'https://Stackoverflow.com/users/1494', 'pm_score': 3, 'selected': False, 'text': '<p>Putting the function definition in the class body is equivalent to marking a function with the inline keyword.  That means the function may or may not be inlined by the compiler.  So I guess the best answer would be &quot;maybe&quot;?</p>\n'}, {'answer_id': 21326, 'author': 'Wilka', 'author_id': 1367, 'author_profile': 'https://Stackoverflow.com/users/1367', 'pm_score': 5, 'selected': False, 'text': '<p>The short answer is yes. Any function can be declared inline, and putting the function body in the class definition is one way of doing that. You could also have done:</p>\n<pre><code>class Foo \n{\n    int* p;\npublic:\n    Foo();\n    ~Foo();\n};\n\ninline Foo::Foo() \n{ \n    p = new char[0x00100000]; \n}\n\ninline Foo::~Foo()\n{ \n    delete [] p; \n}\n</code></pre>\n<p>However, it\'s up to the compiler if it actually does inline the function. VC++ pretty much ignores your requests for inlining. It will only inline a function if it thinks it\'s a good idea. Recent versions of the compiler will also inline things that are in separate .obj files and not declared inline (e.g. from code in different .cpp files) if you use <a href="http://msdn.microsoft.com/en-us/magazine/cc301698.aspx" rel="nofollow noreferrer">link time code generation</a>.</p>\n<p>You could use the <a href="http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx" rel="nofollow noreferrer">__forceinline</a> keyword to tell the compiler that you really really mean it when you say &quot;inline this function&quot;, but it\'s usally not worth it. In many cases, the compiler really does know best.</p>\n'}, {'answer_id': 21327, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 2, 'selected': False, 'text': '<p>To the same extent that we can make any other function inline, yes.</p>\n'}, {'answer_id': 222406, 'author': 'Rodney Schuler', 'author_id': 6188, 'author_profile': 'https://Stackoverflow.com/users/6188', 'pm_score': 2, 'selected': False, 'text': '<p>To inline or not is mostly decided by your compiler.  Inline in the code only hints to the compiler.<br>\nOne rule that you can count on is that virtual functions will never be inlined.  If your base class has virtual constructor/destructor yours will probably never be inlined.</p>\n'}]
['https://Stackoverflow.com/questions/21303', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1556/']