dimanche 12 mars 2017

How do deal with error: invalid initialization of non-const reference of type ‘long int&’ from an rvalue of type ‘long int’ in c++11?

a.cpp

namespace A{
void f(long dimension, vector<long>* v){
... // modify v 
}
}

b.cpp

namespace B{
class BB{ 
 // here I omit ctor dtor, etc.
 public:
     void g(){
          vector<long> v[4];
          A::f(v);
     }
};
}

When I call B::g() through BB's instance, I got following compile error in the member function ‘void B::BB::g()'

error: invalid initialization of non-const reference of type ‘long int&’ from an rvalue of type ‘long int’

How should I manage this code?

Aucun commentaire:

Enregistrer un commentaire