0
Why base class object cannot call protected method
Hi, Why is it an object of the base class cannot call the protected method in this code: https://code.sololearn.com/c74t4H63mq96/#cpp I could understand if the object was from a derived class or unrelated class, but shouldn't a member object be able to call a member function?
2 Respostas
+ 2
Not from outside of it's member class. The object may contain the protected properties but that's still only inside the scope of its own class/sub classes.
int main is not inside the class, so when you create the object you can only access the public properties. Only derived classes or the class itself can access protected.
Change it to public and it will work.
0
Ah, that makes sense - main() is not a member of the class. Thanks.