hchchc6016 2016-05-06 07:50 采纳率: 91.2%
浏览 1466
已采纳

LNK2001一个无法解析的外部命令还有>=不能转化的问题

图片说明

 #include<iostream>
#include<string>
#include<map>
#include<cstdlib>

using namespace std;

class User
{
public:
    string rank[3] ={ "beginner", "professional", "expert"};
    string get_name();
    void login();
    void logout();
    bool is_online();
    int get_login_times();
    int get_played_matches();
    int get_won_matches();
    int get_won_ratio();
    string get_rank();
    void play_with(User* another, bool win);
    static User *getUser();// To get the guest
    static User *getUser(string name);// To get the user
    static map<string,User*>user;
private:
    string name_;
    int login_time;
    int played_matches;
    int won_matches;
    bool is_login;
};
string User::get_name()
{
    return this->name_;
}
void User::login()
{
    this->is_login = 1;
}
void User::logout()
{
    this->is_login = 0;
}
bool User::is_online()
{
    return this->is_login;
}
int User::get_login_times()
{
    return this->login_time;
}
int User::get_played_matches()
{
    return this->played_matches;
}
int User::get_won_matches()
{
    return this->won_matches;
}
int User::get_won_ratio()
{
    return played_matches
            ? double(this->won_matches) / (this->played_matches) * 100
            :0.0;
}

string User::get_rank()
{
    if (this->played_matches>= 50&& this->get_won_ratio >= 70)
        return User::rank[1];
    if (this->played_matches >= 100 && this->get_won_ratio >= 80![图片说明](https://img-ask.csdn.net/upload/201605/06/1462520992_907853.png))
        return User::rank[2];
    else
        return User::rank[0];

}
void User::play_with(User* another, bool win)
{
    if (this->is_login&&another->is_login)
    {
        this->played_matches++;
        another->played_matches++;
        win ? (this->won_matches++) : (another->won_matches++);
    }
}

User* User::getUser()// To get the guest
{
    User* p = new User;
    p->is_login = 1;
    p->login_time = 1;
    p->name_ = "guest";
    char buffer[16];
    static int id = 0;
    _itoa(id++, buffer, 10);
    p->name_ += buffer;
    p->played_matches = 0;
    p->won_matches=0;
    user[p->name_] = p;
    return p;
}
User* User::getUser(string name)// To get the user
{
    map<string, User*>::iterator it;
    it = user.find(name);
    if (it != user.end())
        return it->second;
    else
    {
        User* p = new User;
        p->is_login = 1;
        p->login_time = 1;
        p->name_ = name;
        p->played_matches = 0;
        p->won_matches=0;
        user[p->name_] = p;
        return p;
    }
}
int main()
{
    User *guest0 = User::getUser();
        User *guest1 = User::getUser();
        guest0->login();
        guest0->is_online(); // true
        guest0->logout();
        guest0->is_online(); // false
        guest1->get_login_times(); // 0
        User *maoge = User::getUser("Maoge");
        maoge->get_name(); // Maoge
        maoge->login();
        maoge->logout();
        maoge->login();
        maoge->login();
        maoge->get_login_times(); // 2
        User *maogeCopy = User::getUser("Maoge");
        User *kuanye = User::getUser("Kuanye");
        kuanye->play_with(maoge, true);
        kuanye->get_won_matches(); // 0
        kuanye->login();
        kuanye->play_with(maoge, true);
        kuanye->get_won_matches(); // 1
        maogeCopy->get_played_matches(); // 1
        return 0;
}
  • 写回答

1条回答 默认 最新

  • threenewbee 2016-05-06 15:42
    关注

    this->get_won_ratio
    ->
    this->get_won_ratio()

    还有一些类似的错误,照着一样的修改

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的