我想调用一个对象的另一个类的成员函数,但我似乎无法弄清楚它是如何工作的。至于它应该如何工作的示例代码:C++中的类成员函数指针
Class A {
void somefunction(int x);
}
Class B : A {
void someotherfunction(int x);
}
Class C {
void x() {
callY(&ofthefunction);
} //here you call the function, you dont have an object yet, and you don't know the argument yet, this will be found in function callY
void Y(*thefunction) {
find int x;
if(something)
A a = find a;
a->thefunction(x);
else
B b = find b;
b->thefunction(x);
}
}
我希望这是SENCE,也可以在2种方法,Y1和Y2分裂这一点,但看到90%的代码是相同的(发现在XML文件中的东西),只有对象和参数保存它是不同的,我想这样做
你希望是有道理?不,它不。发布至少可编译的代码。如果你的代码甚至没有编译,那么我们应该假定你对C++的知识,有这么多的语法错误和所有? – Nawaz 2011-05-19 11:56:03