以下是我的测试代码。我只想知道点是什么类型。但是在“bool instanceOf(A* msg)”行编译时出现错误。如何纠正它。谢谢。
#include <iostream>
using namespace std;
class A
class B : public A
class C : public A
template <class T>
bool instanceOf<T>(A* msg)
{
T *tmp = dynamic_cast<T *>(msg);
if(NULL == tmp)
return false;
return true;
}
void resolveMsgType(A* msg)
{
if(instanceOf<B>(msg))
{
cout<<"this is class B"<<endl;
}else if(instanceOf<C>(msg)){
cout<<"this is class C"<<endl;
}else{
cout<<"error"<<endl;
}
}
int main()
{
A *a;
a = new B();
resolveMsgType(a);
a = new C();
resolveMsgType(a);
return 0;
}