I have a class or struct, lets say, Container, with the following structure:
template <typename type> struct Container {
vector <type *> v;
...
functions
...
type* operator[] (int i) { // not sure about this
return (v)[i];
}
};
where type can be a standard type or a custom defined class or struct.
This struct is supposed to work like this:
Container<type> * c(10);
c->function(); // calls a function that iterates over the elements of v
If I want to access individual elements of the vector, I can call
c->v[0]->function()
where function is a member of the type class; This works like expected; however, it could be simplified to
c[0]->function()
since the [] operator, as defined by me, would return a pointer to the contained class and not the container itself, but the compiler still complains that the container class has no member called "function". This is not a big issue, as can be easily avoided with a different syntax, but makes me think that I have some fundamental misunderstanding on how pointers and references works. What would be a proper way to define the [] operator here and what am I missing? Thank you in advance
EDIT: I edited the question to reflect my actual code