我有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;

09-26 19:51
查看更多