【发布时间】:2011-01-24 15:52:19
【问题描述】:
是否可以通过重载参数的运算符逗号来构造函数的可变参数?我想看一个例子如何做到这一点..,也许是这样的:
template <typename T> class ArgList {
public:
ArgList(const T& a);
ArgList<T>& operator,(const T& a,const T& b);
}
//declaration
void myFunction(ArgList<int> list);
//in use:
myFunction(1,2,3,4);
//or maybe:
myFunction(ArgList<int>(1),2,3,4);
【问题讨论】:
-
为什么需要使用逗号操作符?例如。 Boost.Assign 已经为您提供了简洁的语法,但它使用了
operator()。 -
因为我希望使用简单如 MyFunction(1,2,3) 而不是 MyFunction(boost::list_of(1)(2)(3))
标签: c++ operators arguments variadic comma-operator