C++ A nonstatic member reference must be relative to a specific object

BR3TON picture BR3TON · Mar 28, 2015 · Viewed 40.7k times · Source
Vector2D tankPos = Tank_b017191c::GetTankPosition();

I am trying to call a function from a different class but I am getting this error:

47 IntelliSense: a nonstatic member reference must be relative to a specific object e:\Repos\GameAI\GameAI\PathFinder_b017191c.cpp 113 21 GameAI

I have included Tank_b017191c.h in my header file but not getting very far..

Answer

Vlad from Moscow picture Vlad from Moscow · Mar 28, 2015

It seems that member function GetTankPosition is a non-static member function. You have to call it with using an instance of the class as for example

Tank_b017191c tank;
Vector2D tankPos  = tank.GetTankPosition();

or

Tank_b017191c tank( /* some arguments */ );
Vector2D tankPos  = tank.GetTankPosition();