Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Using p->a would only let you access public variables of A. Since a is a protected variable, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as JonJon noted.

Using p->a would only let you access public variables of A. Since a is a protected variable, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

Using p->a would only let you access public variables of A. Since a is a protected variable, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

deleted 5 characters in body
Source Link
djeidot
  • 4.7k
  • 5
  • 45
  • 46

Using p->a is using thewould only let you access public versionvariables of the variableA. If you wanted to use theSince a is a protected versionvariable, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

Using p->a is using the public version of the variable. If you wanted to use the protected version, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

Using p->a would only let you access public variables of A. Since a is a protected variable, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

added 76 characters in body
Source Link
djeidot
  • 4.7k
  • 5
  • 45
  • 46

Using p->a is using the public version of the variable. If you wanted to use the protected version, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

Using p->a is using the public version of the variable. If you wanted to use the protected version, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Using p->a is using the public version of the variable. If you wanted to use the protected version, you should use cout << a, since a is inherited in class B.

I think you could use cout << p->a by friending class B.

Or by using a pointer to B instead of a pointer to A, as Jon noted.

Source Link
djeidot
  • 4.7k
  • 5
  • 45
  • 46
Loading