【发布时间】:2009-05-06 21:50:52
【问题描述】:
所以我有这段代码,为了方便起见,我希望它的构造函数的默认参数是 int 类型和 0。(我的项目的一个类中有更多参数,其中一个是可选的,我没有'不想写两次构造函数,因为它很大)
class mama{
public:
template<typename x> mama(x i=int(0)){}
};
int main(){
mama x;
}
这不起作用,因为它说它找不到构造函数,所以我还有其他方法可以做到这一点吗?
error: no matching function for call to ‘mama::mama()'
note: candidates are: mama::mama(const mama&)
【问题讨论】:
标签: c++ constructor templates default parameters