我有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
,该函数返回vector<int>
。改用static vector<int> def{};
或static vector<int> def;