C++数据类型错误
每当我运行这个时,我都会遇到编译器错误...我很确定这只是我忽略的一些愚蠢的事情,所以我想我会让你们尝试一下。
#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 ===|
I keep getting a compilier error whenever I run this... I am quite sure it is just something stupid that I am overlooking, so I though I would let you guys try.
#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;
}
I keep getting these errors:
|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 ===|
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在程序接近尾声时,您关闭的大括号数量比打开的大括号数量还要多。您需要删除 return 0; 之前的大括号。
此外,您还需要在结束大括号后用分号终止
class hi
的定义括号,位于main() 定义之前。
Near the end of your program you are closing more curly brackets than you have opened. You need to remove the curly bracket right before
return 0;
Also you need to terminate your definition of
class hi
with a semicolon after the closing curly bracket, right before the definition ofmain()
.您忘记了类定义后的分号。
You forgot the semi-colon after your class definition.