Question

I have a c++ project which has a class called A. I also have a header file, called Definitions.h.

I wrote the following code in the header file:

A* aClass;

And in the main of the application, I write:

aClass = new A();

This gives me the redefinition errors of class A by the other classes which use it.

So, after searching the web, I found out that the extern keyword should be added to the deceleration, so I modified the header file's class deceleration into this:

extern A* aClass;

Now I'm getting LNK2001 errors.

What am I missing?

Was it helpful?

Solution

I need to see your code to completely understand where the error might be, but you could try this:

In the header:

extern A* aClass;

In the main.cc, before the main function:

A* aClass;

and inside the main function:

int main()
{
...
aClass = new A();
...
}

Hopefully that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top