-3

I have a simple 2 dimensional vector class, which is implemented as inline functions/operators.

However when I want to instantiate my Vector with no parameters I get Unresolved externals error and I'm not sure why. However, when I use other constructor with parameters it's ok.

This is my class:

class Vector2
{
public:
   float x;
   float y;

public:
   //Constructors
   Vector2() : x(0.0f), y(0.0f) {}
   Vector2(const float _x, const float _y) : x(_x), y(_y) { }
};

Creating instance which causes error:

Vector2 a();

But when instantiating with other constructor it's ok. This also works:

Vector2 a = Vector2();

I'm getting this:

1>main.obj : error LNK2019: unresolved external symbol "class GreenEye::Maths::Vector2 __cdecl a(void)" (?a@@YA?AVVector2@Maths@GreenEye@@XZ) referenced in function main
1>X:\Development\Projects\Engine\x64\Debug\Test.exe : fatal error LNK1120: 1 unresolved external

Any ideas? Thanks.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
mezo
  • 423
  • 1
  • 7
  • 19

1 Answers1

5

It's because you are not instantiating an object using the following:

Vector2 a();

This is actually a function declaration which is why it's complaining about the missing function at link time.

To create an object using the default constructor it should be:

 Vector2 a;
Scott
  • 178
  • 1
  • 9