The short answer is yes. Any function can be declared inline, and one way to do this is to use the body of the function in the class definition. You could also do:
class Foo { int* p; public: Foo(); ~Foo(); }; inline Foo::Foo() { p = new char[0x00100000]; } inline Foo::~Foo() { delete [] p; }
However, it is up to the compiler if it really performs an inline function. VC ++ largely ignores your inlining requests. It will only be a built-in function if she thinks it is a good idea. In the latest versions of the compiler, elements that are in separate .obj files and are not declared inline (for example, from code in different .cpp files) will also be embedded if you use the code generation link time .
You can use the __ forceinline keyword to tell the compiler that you really mean it when you say "embed this function", but itβs usually not worth it. In many cases, the compiler really knows better.
Wilka Aug 21 '08 at 22:12 2008-08-21 22:12
source share