externclass myclass; and class myclass; mean the same thing. The extern is redundant. This is known as a forward declaration.
You can't use a class that's only been forward declared. The compiler needs to be able to see the full declaration at the point of usage. Even something like this will fail to compile:
1 2 3 4 5 6 7
class A;
int main(){
A a;
}
class A{};
You have to move the declaration of myclass to core.h.
A class definition can go into the header file just fine:
1 2 3 4 5
// It is fine to put this in a header file.
class MyClass
{
int m_myInt;
};
A non-const object declaration should not be put into a header file; if you want to make it a global, you will have to follow the same rules as for a global primitive variable:
1 2 3 4 5
int myGlobalInt; // In a header file, this will give linker errors for multiple definitions
externint myGlobalInt2; // In a header file, this will declare a global variable of type int
MyClass myGlobalClass; // In a header file, this will give linker errors for multiple definitions
extern MyClass myGlobalClass2; // In a header file, this will declare a global variable of type MyClass
Does that explain things more clearly?
Insert usual warnings about global variables rarely being a good idea here.
Edit: Not sure why this is in the Windows Programming forum, as there's nothing Windows-specific about any of this.