wrote:
>
> Hi list,
>
> As a C++ newbie, I have a question about static member functions.
> Suppose I have the following class definition:
>
> class MyClass
> {
> public:
> static void MyFunc();
> };
>
> static void MyClass::MyFunc()
> {
> // Do something useful here
> }
>
> Now I would like to enforce static usage of this function (i.e. if an
> instance of this class is created, it should not be possible to use
> MyFunc on that instance (might throw an exception), only
> MyClass::MyFunc() should work)
>
> Since static functions don't have access to the this prointer, I can't
> check whether the function is invoked from an instance or as a static.
> Does someone know a solution to this?
There is no real solution. Maybe because there really is no solution needed.
Just curious: Why do think there is a problem in practice?
A static member function is just a free standing function residing
in the class scope. So if you can live with dropping that scope, just
make it a free standing function.
--
Karl Heinz Buchegger