說我有函數指針?
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
成員函數指針與自由函數指針不同。 – chris