J
James Allsopp
Hi,
I have a list of item objects which I'm trying to find which of these
objects are close to each other. The data in these objects does not
change. I const::iterate though the vector these are stored in, and
where the condition is met, create a linker object in another class. I
don't want to recreate the classes, just store a reference to them.
The code from the linker is
class linker{
public:
linker( const item &spectra, const item & core, double
distance):spectra(spectra),core(core),distance(distance){};
const item & spectra;
const item & core;
double distance;
int toString() const;
};
but get the following errors:
query.cpp:44: error: non-static reference member ‘const item&
linker::spectra’, can't use default assignment operator
query.cpp:44: error: non-static reference member ‘const item&
linker::core’, can't use default assignment operator
How do I get round this? item is a very simple class, shown below.
Thanks,
James
class item{
public:
item(std::string l, std::string lon, std::string lat);
std::string label;
double glon;
double glat;
string print() const ;
};
item::item(std::string l, std::string lon, std::string lat)
{
label=l;
char *t;
glon=strtod(lon.c_str(),&t);
glat=strtod(lat.c_str(),&t);
}
string item:
rint() const
{
stringstream s;
s << label << "\t" << glon <<"\t" << glat << endl;
return s.str();
}
I have a list of item objects which I'm trying to find which of these
objects are close to each other. The data in these objects does not
change. I const::iterate though the vector these are stored in, and
where the condition is met, create a linker object in another class. I
don't want to recreate the classes, just store a reference to them.
The code from the linker is
class linker{
public:
linker( const item &spectra, const item & core, double
distance):spectra(spectra),core(core),distance(distance){};
const item & spectra;
const item & core;
double distance;
int toString() const;
};
but get the following errors:
query.cpp:44: error: non-static reference member ‘const item&
linker::spectra’, can't use default assignment operator
query.cpp:44: error: non-static reference member ‘const item&
linker::core’, can't use default assignment operator
How do I get round this? item is a very simple class, shown below.
Thanks,
James
class item{
public:
item(std::string l, std::string lon, std::string lat);
std::string label;
double glon;
double glat;
string print() const ;
};
item::item(std::string l, std::string lon, std::string lat)
{
label=l;
char *t;
glon=strtod(lon.c_str(),&t);
glat=strtod(lat.c_str(),&t);
}
string item:
{
stringstream s;
s << label << "\t" << glon <<"\t" << glat << endl;
return s.str();
}