Quote Originally Posted by serthy View Post
PHP Code:
#include <iostream>

//forward declerations of derived classes
class Sphere;
class 
Box;

class 
Volume //my base class
{
    public:

        
//virtual, non-base-class methods
        
virtual void checkCollision( const Volume) const = 0;
        
virtual void checkCollision( const Sphere) const = 0;
        
virtual void checkCollision( const Box) const = 0;
}

class 
Sphere : public Volume //derived 1
{
    public:

        
void checkCollision( const Volume) const
        {
            
std::cout << "redo: sphere vs volume" << std::endl;

            return 
v.checkCollision( *this );
        }

        
void checkCollision( const Sphere) const
        {
            
std::cout << "sphere vs sphere" << std::endl;
        }

        
void checkCollision( const Box) const
        {
            
std::cout << "sphere vs box" << std::endl;
        }
}

class 
Box : public Volume //derived 2
{
    public:

        
void checkCollision( const Volume) const
        {
            
std::cout << "redo: box vs volume" << std::endl;

            return 
v.checkCollision( *this );
        }

        
void checkCollision( const Sphere) const
        {
            
std::cout << "box vs sphere" << std::endl;
        }

        
void checkCollision( const Box) const
        {
            
std::cout << "box vs box" << std::endl;
        }
}

int mainint argCount charargs[] )
{
    
Volume v;
    
Sphere s;
    
Box b;

    
//doesnt work, because of virtual = 0; methods in base class, comment them out then
    
std::cout << "VOLUME:" << std::endl;

    
v.checkCollision);
    
v.checkCollision);
    
v.checkCollision);

    
std::cout << "SPHERE:" << std::endl;

    
s.checkCollision);
    
s.checkCollision);
    
s.checkCollision);

    
std::cout << "BOX:" << std::endl;

    
b.checkCollision);
    
b.checkCollision);
    
b.checkCollision);

My understanding of double dispatch, is there an easier and maybe more dynamic method (for adding new derived classes?) without any casting methods?
You can get the double dispatch code link here : https://gist.github.com/s3rvac/ddb2a0ffc6bcc1d3b2f6
Without type cast.