#ifndef INCLUDED_PRIVABLIC_H #define INCLUDED_PRIVABLIC_H namespace privablic { // Generate a static data member of type Stub::type in which to store // the address of a private member. It is crucial that Stub does not // depend on the /value/ of the the stored address in any way so that // we can access it from ordinary code without directly touching // private data. template struct member { static typename Stub::type value; }; template typename Stub::type member::value; // Generate a static data member whose constructor initializes // member::value. This type will only be named in an explicit // instantiation, where it is legal to pass the address of a private // member. template struct private_member { private_member() { member::value = x; } static private_member instance; }; template private_member private_member::instance; template struct func { /* export it ... */ typedef typename Stub::type type; static type ptr; }; template typename func::type func::ptr; template struct private_method : func { /* fill it ... */ struct _private_method { _private_method() { func::ptr = p; } }; static _private_method private_method_obj; }; template typename private_method::_private_method private_method::private_method_obj; } #endif