说我有
class B{ //base class
}
class A : public B{ //derived class
}
我还有一个返回指向 B 类的指针的函数
B* returnB(){
B * object = new A; //pointer of base class allocate object of derived class
return object;
}
现在,当我尝试创建指向函数 B* 的指针时,出现错误
B* (*randomFunction)();
randomFunction = returnB;
Visual Studios 不会编译。
1 IntelliSense: a value of type "B*(MediaFactory::*)()" cannot be assigned to an entity of type "B*(*)()" c:\Users\...\mediafactory.cpp 35