0

I am working on a school project and I am running into a linker error of 'unresolved external symbol' I have two files; math.h and math.cpp. I am trying to declare some arrays in the namespace in math.h, but I am getting linker error from this. In my math.h:

namespace domath
{
extern float alpha1[];
extern Vector ecth[];
}

In my math.cpp:

#include math.h

float alpha1[];
Vector ecth[];

What can I do to fix? I cannot assign a value like alpha1[] = {1}, because I do not know the value it will have. Thank very much in advance!!

1 Answers1

0

You declare the arrays in the domath namespace, but define them in the global namespace. Try this instead:

// math.cpp

#include math.h

namespace domath
{
float alpha1[];
Vector ecth[];
}

The other reason it doesn't work is that you don't specify the size of the arrays. Either give them a fixed size up front, or declare them as pointers instead, or – typically best in C++ – use std::vector.

Thomas
  • 174,939
  • 50
  • 355
  • 478
  • 1
    Stll did not work :(. Note that I'm changing the value of the arrays later in the code, such as; domath::ecth[alpha1->GetIndex()] = 9; – Tucker Besch Jan 13 '18 at 19:26