Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

non-static

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..

like image 791
BR3TON Avatar asked Mar 28 '15 08:03

BR3TON


2 Answers

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();
like image 79
Vlad from Moscow Avatar answered Nov 14 '22 23:11

Vlad from Moscow


You need to have something like this:

Tank_b017191c tank; // you first need to create an object of this class
Vector2D tankPos = tank.GetTankPosition();
like image 29
ucsunil Avatar answered Nov 15 '22 01:11

ucsunil