>Can the main() call be embedded within a class?
You need to make the distinction between a function declaration, a function definition, and a function call. What your example does is declare a member function with the same signature as the global main. However, it's not the same function as the global main. Even if you do this, you still need to define a global main as the entry point for your program:
#include <iostream>
class A {
public:
int main() { std::cout<<"Embedded main"<<std::endl; return 0; }
};
int main()
{
std::cout<<"Global main"<<std::endl;
A().main();
} The reason this is legal is because the member function main is in a different namespace than the global main, so they can both coexist in the same program. How smart this is is debatable though since it can cause confusion.
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401