【发布时间】:2017-03-22 14:47:52
【问题描述】:
我有课mizer:
class mizer {
...
public:
...
void getDeviation( vector<double>&, vector<int>& )
...
};
实现:
void mizer::getDeviation( vector<double>& best_mass, vector<int>& best_comb ){
...
}
但有时我不想提供第二个参数best_comb。所以我想设置默认值什么的:
void mizer::getDeviation( ..., vector<int>& best_comb = default )
我试过了:
static vector<int> def();
...
void mizer::getDeviation( ..., vector<int>& best_comb = def )
但它不起作用:
/minimizer/mizer.C:69:69: error:
non-const lvalue reference to type 'vector<int>' cannot bind to a value of unrelated type 'vector<int> ()'double mizer::getDeviation( vector<double>& best_mass, vector<int>& best_comb=def ){
如何设置默认的vector引用变量?
【问题讨论】:
-
在
static vector<int> def();def中是一个函数,而不是一个向量。请参阅“最令人头疼的解析”。 -
@nwp 这与最麻烦的解析没有关系,因为该语法(带括号)只能用于声明成员函数,而不是成员变量。
-
@nwp。谢谢你。对不起我的愚蠢。我知道它应该有效。