extern class & create desktop

Hi, I do not know if this topic is there sometime. So, how to use the external command.

I have files these:
main.cpp
core.h
MyClass.cpp

In main.cpp I want to use myclass
In core.h is written "external class myclass;"
Finally in myclass.cpp is declare myclass

E1: In my case, He writes a mistake and ignore command: extern

Second problem: Does anyone know how to create a new virtual desktop?
Last edited on
extern class 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.
If I understand this, there is no way for the declaration in myclass and use it in the main
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
extern int 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.
Last edited on
I know, thank you. But the second problem concerns windows.
You're talking about this?
https://www.cnet.com/how-to/how-to-use-multiple-desktops-in-windows-10/
You can also quickly add a desktop without entering the Task View pane by using the keyboard shortcut Windows Key + Ctrl + D.
No, I want create new virtual desktop over the original on each
Topic archived. No new replies allowed.