문제

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.

도움이 되었습니까?

해결책

#include <typeinfo>

void Collision()
{
    if (typeid(obj[x][y]) != typeid(B) && typeid(obj[x][y]) != typeid(C)) 
        doStuff();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top