C ++函数调用缺少参数列表错误

时间:2015-05-11 14:19:37

标签: c++ list function arguments call

include<iostream>
include<string>
using namespace std;

class Player 
{
public:
    string name;
    int age;
    string nationality;
    void InputPlayer(Player);
};
class Defender : public Player
{
public:
    void tackle();
};
class Midfielder : public Player
{
public: 
    void pass();
};
class Striker : public Player
{
public:
    void shoot();
};

void Player::InputPlayer(Player p)
{
    cout<<"ENTER PLAYER'S NAME ";
    getline(cin,p.name);
    cout<<endl<<endl<<"ENTER PLAYER'S AGE ";
    cin>>p.age;
    cout<<"ENTER PLAYER'S NATIONALITY ";
    getline(cin,p.nationality);
}
void Defender::tackle()
{
    cout<<"  TACKLE";
}
void Midfielder::pass()
{
    cout<<"  PASS";
}
void Striker::shoot()
{
    cout<<"  SHOOT";
}

int main()
{
    int NumberOfPlayers;
    int x;
    cout<<"ENTER NUMBER OF PLAYERS ";
    cin>>NumberOfPlayers;
    Player P;
    for(int i = 0 ; i < NumberOfPlayers ; i++)
    {
        cout<<endl<<i<<"> "<<endl<<"ENTER INFORMATION OF PLAYER "<<i;
        P.InputPlayer;
        x=rand()%3+1;
        if(x==1) 
        {
            Defender Pd;
            cout<<P.name<<endl<<P.age<<" y.o     "<<endl<<P.nationality<<endl<<"Position: Defender "<<endl;
            Pd.tackle;
        }
        if(x==2) 
        {
            Midfielder Pm;
            cout<<P.name<<endl<<P.age<<" y.o "<<endl<<P.nationality<<endl<<"Position: Midfielder "<<endl;
            Pm.pass;
        }
        if(x==3) 
        {
            Striker Ps;
            cout<<P.name<<endl<<P.age<<" y.o     "<<endl<<P.nationality<<endl<<"Position: Striker "<<endl;
            Ps.shoot;
        }

    }
    system("pause");
    return 0;
}

所以我的代码和Visual Studio 2010说明了

1>f:\program files\visual studio 2010\projects\lab8\lab8\lab8ans.cpp(264): error C3867: 'Player::InputPlayer': function call missing argument list; use '&Player::InputPlayer' to create a pointer to member
1>f:\program files\visual studio 2010\projects\lab8\lab8\lab8ans.cpp(270): error C3867: 'Defender::tackle': function call missing argument list; use '&Defender::tackle' to create a pointer to member
1>f:\program files\visual studio 2010\projects\lab8\lab8\lab8ans.cpp(276): error C3867: 'Midfielder::pass': function call missing argument list; use '&Midfielder::pass' to create a pointer to member
1>f:\program files\visual studio 2010\projects\lab8\lab8\lab8ans.cpp(282): error C3867: 'Striker::shoot': function call missing argument list; use '&Striker::shoot' to create a pointer to member`

请帮助,目的是输入玩家信息并随机输入他们的位置然后输出所有信息,  如果该职位是后卫,则输出&#39;解决&#39;

如果位置是中场,则输出&#39;传递

如果该位置是前锋,则输出&#39;拍摄

1 个答案:

答案 0 :(得分:1)

您需要使用括号调用函数:

 P.InputPlayer();

如果函数/方法正在进行参数,则需要传递它们。最好抓一本C / C ++书。