Pergunta

I have something like this:

class A
{
public:
    A();
    ~A();
};

class B : public A
{
 //stuff
};

class C : public A
{
 //stuff
};

class D : public A
{
 //stuff
};

void Collision()
{
 //obj is a multidimensional array of class A that stores objects from class B, C and D
 if(obj[x][y] != B && obj[x][y] != C) //type name is not allowed
    doStuff();
}

I'm getting the error: type name is not allowed

I know it is not suposed to compare the objects like this, but i dont know how i should do it.

Foi útil?

Solução

#include <typeinfo>

void Collision()
{
    if (typeid(obj[x][y]) != typeid(B) && typeid(obj[x][y]) != typeid(C)) 
        doStuff();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top