#include <iostream> using namespace std; /* TA <-- defines static function / \ | B <-- subclass TA, inherits it so B::StaticFunc can be used. \ / C <-- want to inherit static func from A, subclass B privately */ template <class T> class TA { public: // return ptr to new instance of class T static T * instance() { static T inst; return &inst; } }; class B : public TA<B> { public: void Func() { cout << 'B' << endl; } }; /* HERE: class C : public TA<C> */ class C : public TA<C>, private B { public: void Func() { cout << 'C' << endl; } }; int main() { C test(); B::instance()->Func(); C::instance()->Func(); /* Expected output: B C Actual error: error: `instance' is not a member of `C'| If i do not subclass B with C, then it compiles. However, I need C to provide some other functionality and but a subclassable Singleton */ return 0; }
#include <iostream> using namespace std; /* TA <– defines static function / \ |
Share
I get a different, more reasonable error (with g++ 4.3.3):
This can be fixed by explicitly specifying which version of
instanceshould be used inC: