【发布时间】:2011-02-23 09:42:16
【问题描述】:
我有一个类Managed,其中包含一个函数f,它执行该类的其他函数。
class Managed {
public:
Managed(){}
~Managed(){}
int f( some arguments ); //managed function
private:
int A();
int B();
int C();
};
我想根据 Managed 类的对象的构造方式来管理 f 执行的操作,即使其表现得像这样
int Managed::f (some arguments) {
A();
B();
A();
return 0;
}
或者像这样
int Managed::f (some arguments) {
C();
B();
return A();
}
等等
我需要非常灵活的管理,我需要像编写函数 f 的行为脚本之类的东西。我如何在 C++ 中做到这一点?
【问题讨论】:
-
它非常不清楚。您不能从
void函数返回任何内容。some arguments是什么?他们是否控制f的行为方式?您能告诉我们您要解决什么问题吗? -
抱歉,已更正返回类型。
-
如何在
Managed::f(int arg1)中编写一个开关函数,根据它的参数来完成特定的工作。基于任何类型的对象(即驻留在堆栈/堆上),该方法的功能在实例上调用时不会改变。所以,我不确定你的意思是什么时候,depending on the way the object of class Managed was constructed