C++ 中的错误 C3867
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3979639/
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
Error C3867 in C++
提问by Xturbed1442
My code was working fine until I reloaded the program a few hours later. Now I get these this error:
我的代码运行良好,直到几个小时后我重新加载了程序。现在我得到这些错误:
error C3867: 'player::getxPos': function call missing argument list; use '&player::getxPos' to create a pointer to member
error C3867: 'player::getyPos': function call missing argument list; use '&player::getyPos' to create a pointer to member
错误 C3867:“player::getxPos”:函数调用缺少参数列表;使用 '&player::getxPos' 创建指向成员的指针
错误 C3867:“player::getyPos”:函数调用缺少参数列表;使用 '&player::getyPos' 创建指向成员的指针
This is the code in question:
这是有问题的代码:
if (P->shoot())
{
shotVector.push_back(shot());
eS = shotVector.size();
shotVector[eS-1].initShot(
P->getxPos, // C3867
P->getyPos // C3867
);
}
I'm trying to call two functions from a class called player and these two functions look like this:
我正在尝试从名为 player 的类中调用两个函数,这两个函数如下所示:
int player::getxPos(){
return xPos;
};
int player::getyPos(){
return yPos;
};
What's being done is that I'm trying to ask for the players position and then use that to decide where to shoot from.
正在做的是我试图询问球员的位置,然后用它来决定从哪里射门。
回答by wkl
shotVector[eS-1].initShot(P->getxPos, P->getyPos);
- you are trying to call the getxPos()
and getyPos()
members without ()
.
shotVector[eS-1].initShot(P->getxPos, P->getyPos);
-你试图调用getxPos()
和getyPos()
成员没有()
。
Use getxPos()
and getyPos()
.
使用getxPos()
和getyPos()
。
回答by Adam Batkin
You forgot the parenthesis, which tell the compiler that you want a method call:
你忘记了括号,它告诉编译器你想要一个方法调用:
P->getxPos
vs
对比
P->getxPos()
If you instead used &P->getxPos
, that would give you a pointer to the member function itself.
如果您改为使用&P->getxPos
,那会给您一个指向成员函数本身的指针。
回答by Alex F
shotVector[eS-1].initShot(P->getxPos(), P->getyPos());