C++非静态成员引用必须与特定对象相关

BR3*_*TON 6 c++ non-static

Vector2D tankPos = Tank_b017191c::GetTankPosition();
Run Code Online (Sandbox Code Playgroud)

我试图从一个不同的类调用一个函数,但我收到此错误:

47智能感知:非静态成员引用必须相对于特定对象e:\ Repos\GameAI\GameAI\PathFinder_b017191c.cpp 113 21 GameAI

我在我的头文件中包含了Tank_b017191c.h,但没有达到很远的程度.

Vla*_*cow 3

看来成员函数GetTankPosition是非静态成员函数。您必须使用类的实例来调用它,例如

Tank_b017191c tank;
Vector2D tankPos  = tank.GetTankPosition();
Run Code Online (Sandbox Code Playgroud)

或者

Tank_b017191c tank( /* some arguments */ );
Vector2D tankPos  = tank.GetTankPosition();
Run Code Online (Sandbox Code Playgroud)