R
Ruben Van Havermaet
SomeClass' data member is a Strategy, not a StrategyA. If you changed this
to
StrategyA s_;
Then it will work.
But what if I would want to use some other Strategy? What I really
intended to find out was how to implement "late binding of a function
call" or polymorphism.
(Stroustrup, "The C++ Programming Language", p. 312). The key to this,
as Victor pointed out, is to use references and pointers.
Declaring a pure virtual function makes the class an ADT (abstract data
type). Because you cannot create an object of an ADT, it must have a
default constructor (but that's already there). The problem comes from
trying to give SomeClass a Strategy member. When you do this, a Strategy
object is "constructed" inside SomeClass, which is an error. The SomeClass
constructor error is basically the same; it comes from trying to initialize
an object of the Strategy ADT.
But making it a reference clears this problem out of the way.
Friendly Greetings,
Ruben.