Accessing to attributes of a templated vector while it is an element of another vector in c++

StackOverflow https://stackoverflow.com/questions/22794089

Pergunta

I have a custom vector class which have the following functions, push, pop, print in which the print function will print out all elements in the vector. The private attributes of the vector are m_current(Current iterator), m_size(size of vector) and Datatype m_data(templated).

Now I have another class called Data which have the following attributes, m_date, m_time.

I declared 2 vectors with this.

vector<Data> vect1(10);
vector<Data> vect2(10);

And then, I declare another vector to house these vectors.

vector<vector<Data>> vect3(10);
vect3.push(vect1);
vect3.push(vect2);

My question is, just how do i access the m_time of vect1 through vect3?

Foi útil?

Solução

Assuming your vector class implements operator[], which it should, it's as simple as this:

vect3[0][0].m_time

If the element accessor has an other name, such as get_element(int id), it would be

vect3.get_element(0).get_element(0).m_time

If there is no element accessor function, then congratulations, you have created Write-only memory.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top