I couldn’t find this anywhere on the web so I’m most likely is not the correct way to tackle the issue, but maybe:
I got a class which have the values A and B, I store both of these in a collective vector. Is there a way to only get access to value A from within the vector? Or would I have to create separate vectors for the values?
Someone wanted to see part of my code, so here:
class Read{
friend ostream &operator<<(ostream &,const Read &);
public:
Read(char,float,float,float);
~Read();
private:
char objekt_;
float x_, y_, r_;
};
int main(){
vector<Read> v_read;
while(fin >> objekt >> x >> y >> r){
v_read.push_back(Read(objekt, x, y, r));
}
return 0;
}
Out from that vector I would like to access my objekt_ values in each part of the vector.
Given a vector of
structs with two things in the struct we can do things like:To work with only part of each struct for all the entries in a given
std::vector.