Please consider a pure virtual class like this:
class Foo {
public: virtual int FooBar() = 0;
};
A Java developer would call such a thing an "Interface". Usually, you then program to that interface, e.g. (bad example, sorry):
class Bar {
public: Foo f;
};
class Child : public Foo {
public: int FooBar() { return 1; }
};
Bar b;
b.foo = Child();
This does obviously not work in C++, because an instance of class Foo is created at construction time (but that's not possible, because Foo is an abstract class).
Is there any pattern for "programming to an interface" in C++?
Edit: Clarified the example, sorry.
Baris not a base class ofChild.