I've got two classes, one Measurement
class which contains a vector<double>
and an Experiment
which contains a vector<Measurement>
:
class Measurement {
private:
vector<double> dataSet;
string time_stamp;
public:
const vector<double>& getDataSet() {return dataSet;}
string getTimeStamp() {return time_stamp;}
};
class Experiment {
private:
vector<Measurement> measurements;
public:
const vector<Measurement>& getMeasurements() {return measurements;}
};
In short, I am trying to iterate through each Measurement
in an Experiment
(outer loop), and then through the data in each Measurement
(inner loop).
I found some help at this thread, which is why the member functions getDataSet()
and getMeasurements()
are const &
(to make the iterators compatible).
However when I try to call iter_meas->getDataSet()
, I run into trouble.
int main() {
Experiment expTest(); // experiment already filled with measurements
vector<Measurement>::const_iterator iter_meas;
vector<double>::const_iterator iter_data;
for (iter_meas = expTest.getMeasurements().begin(); iter_meas != expTest.getMeasurements().end(); iter_meas++) {
cout << iter_meas->getTimeStamp() << ','; //this works fine :)
for (iter_data = iter_meas->getDataSet().begin(); iter_data != iter_meas->getDataSet().end(); iter_data++){
// ^^^ here I get the error
// "the object has qualifiers that are not compatible with the member function getDataSet"
// "object type is const measurement"
cout << iter_data << ",";
}
cout << '\n';
}
return 0;
}
I understand that iter_meas
represents a const Measurement
, but I'm not sure why I can't called Measurement::
member functions on it?
I'm using Visual Studio Community 2015.