Question about inheritance

M

maverik

Hi all.

There is one question about inheritance:

I have base class, lets say it is IInterface:

class IInterface {
virtual void foo();
};

and derived class:

class Implementation : public IInterface {
void foo() { do_something(); }

// Many more functions here
void func1();
void func2();
...
void funcN();
};

I want to create class that allows clients to call func1(), ... , funcN
() function, but doesn't allow to call functions from base class (in
our case foo() ). How can I do this?

I try the following:

class IInterface {
public:
virtual void foo() = 0;
};

class Implementation: public IInterface {
public:
void foo() { std::cout << "Implementation::foo();\n"; };
void bar() { std::cout << "Implementation::bar();\n"; };
};

template<class T>
class MyClass : private IInterface, public T {
public:
void tee() {}
};

MyClass<Implementation> c;

but VC 9.0 says me:

error C2259: 'MyClass<T>' : cannot instantiate abstract class

Unfortunately can't test this on gcc.

Of course, I can write MyClass as a copy of Implementation class, but
with private or protected inheritance from IInterface, but
Implementation in real is a big class (and not only one, there is
bunch of such classes).

Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top