c++ - passing vector from one class to other as object -
i have 2 classes net
, ga
, want pass vector ga
net
through main
. consider following code.
class ga { inline vector <double> get_chromosome(int i) { return population[i]; } } class net { int counter; net::setweights(vector <double> &wts){ inphidd = wts[counter]; } } main(){ net.setweights( g.get_chromosome(chromo) ); }
error is:
network.h:43:8: note: void network::setweights(std::vector<double>&) void setweights ( vector <double> &wts ); ^ network.h:43:8: note: no known conversion argument 1 ‘std::vector<double>’ ‘std::vector<double>&’
any idea?
this simple: according standard, const references can bind temporaries.
g.get_chromosome(chromo)
returns temporary, , net::setweights(vector <double> &wts)
tries bind regular reference.
the line network::setweights(std::vector<double>& wts)
should network::setweights(const std::vector<double>& wts)
if you're not going change vector, or network::setweights(std::vector<double> wts)
if do.
one last option move vector around, in case should use move semantics.
Comments
Post a Comment