0

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?

Sam
  • 7,252
  • 16
  • 46
  • 65
Idanis
  • 1,918
  • 6
  • 38
  • 69

1 Answers1

0

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!

MonsieurBeilto
  • 878
  • 1
  • 11
  • 18