【发布时间】:2011-10-18 01:17:56
【问题描述】:
我只有一个非常基础的类,它提供了返回比赛获胜球队的功能。
这里是team.cpp
class teams
{
string teamName;
string teamName2;
int score;
int score2;
public:
teams ();
void set_team1();
void set_team2();
string get_score()
{
if (score > score2)
{
return teamName;
}
else
{
return teamName2;
}
}
private:
void teams::set_team1(string teamName, int score)
{
this->teamName=teamName;
this->score=score;
}
void teams::set_team2(string teamName2, int score2)
{
this->teamName2=teamName2;
this->score2=score2;
}
};
这是我在 main 方法中遇到错误的那一行。我正在尝试创建一个团队对象。
firstTeam.set_team1(teamName, score);
firstTeam.set_team2(teamName2, score2);
Visual Studio 出现并说“错误:没有重载函数的实例“team::set_team1”与参数列表匹配”。
我错过了什么?
这是我得到的确切错误:
1>c:\users\lab8.cpp(31): error C2664: 'void teams::set_team1(std::string,int)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::string'
1> with
1> [
1> _Ty=std::string
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\lab8.cpp(32): error C2664: 'void teams::set_team2(std::string,int)' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::string'
1> with
1> [
1> _Ty=std::string
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> Generating Code...
1>
1>Build FAILED.
【问题讨论】:
-
欢迎来到 Stack Overflow!请提供一个完整的、最小的程序来演示您的问题。摆脱所有没有损坏的东西,然后复制粘贴剩下的东西。请参阅sscce.org 了解更多信息。
-
你能给出来自 Visual Studio 的确切信息吗?这看起来像家庭作业。
-
是的,它的功课,但我只是在特定问题上寻求帮助。我在原始帖子中发布了错误消息。