我有一个Visual Studio 2008 C++ 03项目,我想验证对象是否属于某种类型。验证基础对象是一个特定派生类型
例如:
int main()
{
struct A { virtual ~A() { }; };
struct B : public A { };
struct C : public A { };
A* b = new B();
A* c = new C();
assert(typeof(b) == typeof(B));
assert(typeof(b) != typeof(C));
assert(typeof(c) == typeof(C));
assert(typeof(c) != typeof(B));
assert(typeof(b) != typeof(c));
return 0;
}
有没有办法做到这一点在C++ 03?怎么样?
'assert(typeid(* b)== typeid(B))'似乎工作。谢谢! – PaulH