每当我运行此命令时,我都会不断收到一个更复杂的错误...我可以肯定,这只是我忽略的愚蠢行为,因此尽管我允许您尝试。

#include <iostream>
#include <string>

using namespace std;

class hi
{
public:
    string run()
    {
        hi = "Hello.";
        return hi;
    }
private:
    string hi;
}

int main()
{
    bool end = false;
    string in = "";
    string out = "";

    hi hi;

    while(end != true)
    {
        cout << "Input a Command: ";
        cin >> in;
//        if(in == "help")
//        {
//            out = help.run;
//        }
        if(in == "hi")
        {
            out = hi.run;
        }

        cout << out;
        in = "";
    }
    return 0;
}

我不断收到这些错误:
|6|error: new types may not be defined in a return type|
|6|note: (perhaps a semicolon is missing after the definition of 'hi')|
|18|error: two or more data types in declaration of 'main'|
||=== Build finished: 2 errors, 0 warnings ===|

最佳答案

在程序结束时,您要关闭的花括号比打开的要多。您需要在 return 0;之前删除右括号

此外,您还需要在右花括号后紧接class hi定义之前,以分号终止main()的定义。

关于c++ - 数据类型的C++错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8772551/

10-14 00:08