注册 登录
编程论坛 C++教室

c++简单问题

zzjking 发布于 2007-10-15 09:59, 454 次点击

比如:
class test
{
public:
test();
void funa();
void funb();
void func();
.
.
.
};
这是一个简单的类
按一般
int main()
{
test a;
a.funa();
a.funb();
.
.
return 0;
}

但是,如果类中有一万个方法,总不能在MAIN函数里全这么写把?
怎么才能在MAIN函数中不写多少东西,又能完成所需要的所有方法呢?

3 回复
#2
HJin2007-10-15 10:42
0. The thing is that you won't write 10 thousand methods for class, if you don't need that many; i.e., each method of a class should have useful meanings.

1. If you really want to do what you said, you can use function pointers array/vector, and using a loop to call each method, which is as efficient as you wrote 10 thousand methods directly.
#3
孤魂居士2007-10-15 12:39
英语看不懂啊 斑竹```哪位斑竹能翻译下哦
#4
hhei2007-10-15 12:51
我来翻译:
1. 问题是如果你不需要的话,你不会在你的类里面写10000个函数,每个函数都应该是有用的。(没用写进去干嘛,吃多了?)

2. 如果你真要写的话,可以用函数指针数组,通过指针,循环调用你的函数。
1