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

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

Vector2D tankPos = Tank_b017191c::GetTankPosition();

我正在尝试从另一个 class 调用一个函数,但出现此错误:

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

我已经在我的头文件中包含了 Tank_b017191c.h,但还不够..

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

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

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

你需要有这样的东西:

Tank_b017191c tank; // you first need to create an object of this class
Vector2D tankPos = tank.GetTankPosition();