2 hchchc6016 hchchc6016 于 2016.05.06 15:50 提问

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![图片说明](http://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;
}

2个回答

caozhy
caozhy   Ds   Rxr 2016.05.06 23:42
已采纳

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

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

CSDNXIAOD
CSDNXIAOD   2016.05.06 16:02

Qt XXXr.obj : error LNK2001: 无法解析的外部符号 3 个无法解析的外部命令问题
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!