【发布时间】:2020-03-31 21:35:02
【问题描述】:
我有一个名为 Party 的类,其中包含一个名为 player 的私有变量,它是向量类型,sting。
class Party
{
vector <string> players;
public:
Party (string party_name, string boss) {};
~Party() {};
vector<string> getNames() { return players; };
void setNames (const vector<string> &new_players) { players=new_players; }
}
我想编写一个友元函数,它会显示变量 P(也就是具有“名称”变量为私有的类)是否是党的党。
void part_of_party (Party &party, P name)
{
bool found=false;
for (int i=0; ( found==false && i<party.name.size() ); ++i)
{
if ( (party.name[i]).compare(name.getName()) == 0)
{
found==true;
};
}
if (found==true) { /// }
else { //// }
}
编译器没有显示任何错误,但屏幕上没有显示任何消息(如预期的那样)。
你有什么想法吗? 谢谢。
【问题讨论】:
标签: c++ function for-loop if-statement vector