为什么它不编译,但在cpp.sh上编译

Why it dont compile, but compile on cpp.sh

本文关键字:编译 cpp sh 但在 为什么      更新时间:2023-10-16

我有那个QT:

Qt Creator 4.1.0基于Qt 5.7.0 (MSVC 2013, 32位)

Built on Aug 24 2016 14:56:50

下一个代码:

#include <iostream>
using namespace std;
[enter image description here][1]
// универсальный полиморфизм (шаблон)
template <typename T>
class value {
public:
    T val;
};
// динамический полиморфизм
class var {
public:
    virtual char type(){return 'U';}
};
class Int:public var {
public:
    char type(){return 'I';}
};
class String:public var {
public:
    char type(){return 'S';}
};
class Float:public var {
public:
    char type(){return 'F';}
};
class M:public var{};

std::string gettype(var* opt){
    if (opt->type() == 'U'){
        return "unknown";
    } else if (opt->type() == 'I') {
        return "int";
    } else if (opt->type() == 'S'){
        return "string";
    } else if (opt->type() == 'F'){
        return "float";
    }
}
int main(int argc, char *argv[]){
    // универсальный полиморфизм
    value<int> n;
    n.val = 5;
    value<string> s;
    s.val = "text";
    cout << n.val << endl;
    cout << s.val << endl;
    // динамический полиморфизм
    var* a = new Int();
    var* b = new String();
    var* c = new Float();
    var* x = new M();
    cout << gettype(a) << endl;

    return 0;
}

它在cpp.sh上运行良好,但在我的QT上win8.1不工作。

"二元" & lt; & lt;":无法找到操作数类型为" STD:: string "的操作符(或无法接受转换)"

您可能需要使用:

包含string.h
#include <string>

然后我将删除[enter image description here][1]行,我不知道它是做什么的,它不是c++代码。