I am trying to make a class that will represent two different behaivours at the same time. Like the following:
class IMouse {
public:
virtual void Walk() const = 0;
};
class TSimpleMouse : public IMouse {
public:
void Walk() const;
};
class IBat {
public:
virtual void Fly() const = 0;
};
class TSimpleBat : public IBat {
public:
void Fly() const;
};
template <class TMouse, class TBat>
class TSuperCreatureImpl {
public:
void Do() const {
Walk();
Fly();
}
};
typedef TSuperCreatureImpl<TSimpleMouse, TSimpleBat> TSimpleSuperCreature;
This is important for me to have the behaviour by deafult (method Do), because I would like to make different typedefs. It seems to be very simple.
But I also would like methods Fly and Walk to have parameters (velocity, for example). How should I modify the architecture to have an opportunity to use many typedefs for different creatures?
How to change the architecture if there are no default constructors for Mouse and Bat?
Thanks a lot.
You could give the functions default parameters…
EDIT
One option is to do something like this:
If you want to use
doubles, they’re not allowed as template arguments (at least not in C++03), but as a hack you could accept a pair of numbers and divide them inside the template, or more properly you could provide a policy class….