Question sur accès protégé

Re: Question sur accès protégé

by Sepand Kashani -
Number of replies: 0

Il s'agit d'une subtilité de l'accès protégé. D'après la spécification C++:

Protected members form the interface of a class to its derived classes (which is distinct from the public interface of the class).
A protected member of a class is only accessible
1) to the members and friends of that class;
2) to the members of any derived class of that class, but only when the class of the object through which the protected member is accessed is that derived class or a derived class of that derived class.
 

Donc selon 2), 'a += autreA.a' n'est pas un appel permis.

[Raison (Avancé): si cette opération était permise, alors il serait possible de modifier d'autres classes qui hériteraient potentiellement de 'A'.]