On Sun, 03 Jun 2012 14:03:21 -0400, DSF <nota...@address.here>
wrote:
Thanks to all who responded. I kind of suspected it related to the
pointer, since I did manage to get f to equal i without the pointer.
Once the fog from the template had lifted from my eyes, I Googled
around for "pointer to base class protected member c++" to learn why
this restriction exists. One of the hits was a forum that had the
scent of "copy of newsgroup" on it, so I went looking here. Mine is a
very oft-asked question!
Once I got my mind around the now obvious fact that the declaration
of an object is not necessarily the only instance of said object, the
reason was clear. Only allowing the this pointer (explicit or implied)
ensures only the current instance's base is accessed.
Are there any bad side effects to declaring D a friend of B (as
below)? In the real world code this example is based on, B and D have
a very close relationship. It also allows me to make "i" and other
data members of "B" private.
By the way, the forum postings with the newsgroup scent came from a
thread posted in this very group last March.
template <class T> class A
{
protected:
T *Tptr;
};
class B
{
friend class D;