I know that this is detrimental to data hiding but theoretically is this allowed ?
main() can very well be a friend of any class. Just declare it as a friend inside the class like you do for other member functions.
So a natural enforcement is to make the constructor private and main() as a friend. means a function named main() in namespace ns. So the real main() becomes irrelevant.
A friend function can be friendly to 2 or more classes. The friend function does not belong to any class, so it can be used to access private data of two or more classes as in the following example. The friend functions can serve, for example, to conduct operations between two different classes.
Friend Keyword in C++You can use the friend keyword to any class to declare it as a friend class. This keyword enables any class to access private and protected members of other classes and functions.
Of course.
main
is an almost completely ordinary function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With