Topic: Access to protected member functions


Author: lang@ind.e-technik.uni-stuttgart.de (Martin Lang)
Date: 11 Nov 1994 12:25:05 GMT
Raw View
Here is some piece of code I'm not sure it's legal.


-------------------------  Begin Code  -----------------------------
class TCountMeter {
public:
protected:
   void HandleMsg(){};
};

class TMsgFilter {
public:
   TMsgFilter(void (TCountMeter::*)()){};
};

class TStdCountMeter : public TCountMeter {
public:
   TStdCountMeter() : fMsgFilter(&TCountMeter::HandleMsg) {};
protected:
   TMsgFilter fMsgFilter;
};

main()
{
}


-------------------------  End Code  --------------------------------


Section 11.5 of the ARM says: "A friend or a member function of a
derived class can access a protected nonstatic member of one
of its base classes only through a pointer to, reference to, or
object of the derived class."

In the example the protected member HandleMsg of the base class
is accessed through a pointer to member function to the base
class. There is no pointer to the derived class involved, so
it should be illegal.


Initialization of class TMsgFilter with &TStdCountMeter::HandleMsg()
should also be illegal, because pointer to member functions of derived
class can not be implicitly converted to pointer to member functions
of base class.

So, is the only way to call function HandleMsg making it public?


Any comments?


Martin

--


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+   Martin Lang                       |   Martin Lang                       +
+   Universitaet Stuttgart, IND       |   University of Stuttgart, IND      +
+   Institut fuer Nachrichtenverm.    |   Institute of Communications       +
+   und Datenverarbeitung             |   Switching and Data Technics       +
+   Seidenstrasse 36                  |   Seidenstrasse 36                  +
+   D-70174 Stuttgart                 |   D-70174 Stuttgart, Germany        +
++++++++++++++++++++++++++++++++++++++|++++++++++++++++++++++++++++++++++++++
+                                                                           +
+                      Phone: +49 711 121 2490                              +
+                      Fax  : +49 711 121 2477                              +
+                      Email: lang@ind.e-technik.uni-stuttgart.de           +
+                                                                           +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++