I wonder is there any cases in a C++ program wherein changing an access specifier (public/protected/private) in the code lead to a change in the behaviour of that program?
Templates allow you to do different things depending on whether a member or method is accesible or not. Just as a random example, consider this:
#include <type_traits>
#include <iostream>
struct foo_private {
private:
foo_private() {}
};
struct foo_public {
public:
foo_public() {}
};
int main() {
std::cout << std::is_default_constructible<foo_private>::value;
std::cout << std::is_default_constructible<foo_public>::value;
}
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