using namespace std;
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
}
int main(void)
{
M a();
cin.get();
}
运行结果为:'M' followed by 'int' is illegal (did you forget a ';'?)
return type of 'main' should be 'int' instead of 'M'
5 个解决方案
#1
M a(); 这是一个函数声明,吧()去掉
#2
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
} //这儿加";"分号
int main(void)
{
M a(); //改为 M a;
cin.get();
}
{
public:
M() {cout<<"i love cpp"<<endl;}
} //这儿加";"分号
int main(void)
{
M a(); //改为 M a;
cin.get();
}
#3
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
};
{
public:
M() {cout<<"i love cpp"<<endl;}
};
#4
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
}; //这儿加";"分号
int main(void)
{
M a; //改为 M a;
cin.get();
return 0; //这里加上返回语句
}
{
public:
M() {cout<<"i love cpp"<<endl;}
}; //这儿加";"分号
int main(void)
{
M a; //改为 M a;
cin.get();
return 0; //这里加上返回语句
}
#5
//改为 M a;
#1
M a(); 这是一个函数声明,吧()去掉
#2
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
} //这儿加";"分号
int main(void)
{
M a(); //改为 M a;
cin.get();
}
{
public:
M() {cout<<"i love cpp"<<endl;}
} //这儿加";"分号
int main(void)
{
M a(); //改为 M a;
cin.get();
}
#3
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
};
{
public:
M() {cout<<"i love cpp"<<endl;}
};
#4
class M
{
public:
M() {cout<<"i love cpp"<<endl;}
}; //这儿加";"分号
int main(void)
{
M a; //改为 M a;
cin.get();
return 0; //这里加上返回语句
}
{
public:
M() {cout<<"i love cpp"<<endl;}
}; //这儿加";"分号
int main(void)
{
M a; //改为 M a;
cin.get();
return 0; //这里加上返回语句
}
#5
//改为 M a;