C++ 非静态成员引用必须相对于特定对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29315276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++ A nonstatic member reference must be relative to a specific object
提问by BR3TON
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
47 IntelliSense:非静态成员引用必须相对于特定对象 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..
我在我的头文件中包含了 Tank_b017191c.h 但并没有走得很远。
采纳答案by Vlad from Moscow
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
似乎成员函数GetTankPosition
是一个非静态成员函数。例如,您必须使用类的实例来调用它
Tank_b017191c tank;
Vector2D tankPos = tank.GetTankPosition();
or
或者
Tank_b017191c tank( /* some arguments */ );
Vector2D tankPos = tank.GetTankPosition();
回答by ucsunil
You need to have something like this:
你需要有这样的东西:
Tank_b017191c tank; // you first need to create an object of this class
Vector2D tankPos = tank.GetTankPosition();