Monday, February 21, 2011

C++ extern class definition

I'm reading some code that goes:

extern class MyClass : BaseClass
{
    ...
} MyInstance;

Does the extern refer to the class declaration or the instance?

From stackoverflow
  • Instance. Classes cannot be extern.

    Although the code smells - this snippet suggests that true declaration of that instance uses a separate class definition. Bad, bad idea - defining the class twice.

    Scott S : Seva nailed it. Separating the instance from the class definition, the extern class does not compile, but extern MyClass MyInstance does.

0 comments:

Post a Comment