[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BUG #1589: The whole concept of forces/move_with_forces/forces_holde
From: |
Gervase Lam |
Subject: |
Re: BUG #1589: The whole concept of forces/move_with_forces/forces_holder needs to be rethought |
Date: |
Wed, 6 Nov 2002 01:05:44 +0000 |
> Subject: Re: BUG #1589: The whole concept of
> forces/move_with_forces/forces_holder needs to be rethought
> From: Ingo Ruhnke <address@hidden>
> Date: 04 Nov 2002 23:21:08 +0100
> class Pingu
> {
> public:
> template<class T>
> void check_collision(const T& col)
> {
> if (col(6, 5))
> std::cout << "Something collided" << std::endl;
> else
> std::cout << "Nothing collided" << std::endl;
> }
> };
>
> struct Coll
> {
> bool operator() (int a, int b) const {
> return a > b;
> }
> };
>
> int main()
> {
> Pingu a;
> a.check_collision(Coll());
> }
Sorry if this is a naive question. Why do member templates have to be
used? Couldn't something like the following do?
/** First, the base class **/
class PinguAction
{
public:
virtual void move_to();
virtual bool check_collision(int a, int b);
}
bool PinguAction::move_to()
{
// blah blah
if (check_collision(a, b))
// blah blah
}
bool PinguAction::check_collision(int a, int b)
{
// "Default" collision function
}
/** An action that has specialised collision checking **/
class PinguAction::AnAction
{
public:
virtual bool check_collision(int a, int b);
}
bool PinguAction::check_collision(int a, int b)
{
// "Overrides" base collision function
}
That's the basics of it. OK, a few small things could be improved here.
But why not use this basic idea rather than member templates?
Thanks,
Gervase.
- Re: BUG #1589: The whole concept of forces/move_with_forces/forces_holder needs to be rethought,
Gervase Lam <=