|
发表于 2009-5-5 01:09:47
|
显示全部楼层
Post by zlbruce;1983367
如果是C++的话,并且可以不使用函数指针的话
[php]
#include <iostream>
#include <vector>
struct test
{
std::vector<int> m_v;
test& operator()(int i)
{
m_v.push_back(i);
return *this;
}
};
int main(int argc, char *argv[])
{
test a;
a(1)(2)(3)(4);
for( size_t i = 0 ; i < a.m_v.size() ; i++ )
{
std::cout << a.m_v << std::endl;
}
return 0;
}
[/php]
LZ也没规定必须要用C和函数指针,只要能实现f()()()就成。
我的脑子太死板了,哈哈
只不过这个代码不是多态的,如要实现BOOST的成员函数指针还得用笨办法。。。
我觉得还得在模版上下手,再研究研究。 |
|