I know that main
can be a friend of a class
:
#include <iostream>
class foo {
friend int main();
int i = 4;
};
int main() {
foo obj;
std::cout << obj.i << std::endl;
}
However, I feel that although this is perfectably allowable it conceals many dangers.
main
a friend of a class?main
as friend of a class should be considered harmful? The choice whether to use or avoid a legal feature becomes moot if the feature is not, in fact, legal. I believe there's serious doubt surrounding this, because the Standard says
The function
main
shall not be used within a program.
There's already a question regarding whether befriending ::main()
is in fact allowed, and you'll find more details in my answer there.