C++类中可以有main()?
最近看同学学JAVA,在一个类中定以了一个main()就可以运行?C++中类中可以有main()吗?一直没有遇到过。
[解决办法]
完全可以
class test
{
public:
int main()
{
puts( "test::main" );
return 0;
}
};
int main()
{
test x;
x.main();
}
#include<iostream>
using namespace std;
class test
{
public:
int main()
{
puts( "test::main" );
return 0;
}
};
int main()
{
test x;
x.main();
system("pause");
}