What does the photoshop plugin do with a char pointer?
How long does the array have to exists?
Do you realize what happens, if the user does:
1 2 3
|
char * a = MyPlugin::AppendExtension( "foo" );
char * b = MyPlugin::AppendExtension( "bar" );
// use a
|
The j and AppendExtension are static members. They do not need any MyPlugin object. Lets assume that you do call delete[] in destructor.
1 2 3 4 5
|
int main() {
MyPlugin x;
MyPlugin y;
// double deletion of what was never allocated?
}
|
The main question: What in header, what not?
The class is defined in the header. The header might be included into multiple translation units. Inlined member function implementations can be there, but the main gist is declaring the interface of the class for the users. Look up Herb Sutter and pimpl idiom about hiding the private parts of a class from the users.
Static member variables cannot be initialized in the header. If the header is included in more than one translation unit, then the definition of the static member will be defined more than once, which is a linker-stage error.
The implementation of the destructor may not always be inlined.
Lets assume that the header is a part of a library. Some programs use and dynamically link the library. Implementation of a member is in the header. You find and fix a bug in the function. The interface does not change. You obviously recompile the library. Every program has to recompile too, for their sources include the header.
Plan B: the implementation is in the source. You fix and recompile the library. Distribute it to user. Done. Programs do not have to recompile, for dynamic linker can link to the new copy too.