I have class A and B.
Class A has some fields. Class B is like:
class B {
public:
A* operator[]( int id ) {
return m_field.at( id );
}
/* also tried this one, but there are the same errors
A*& operator[]( int id ) {
return m_field.at( id );
}
*/
private:
vector<A*> m_field;
};
why am I getting errors while executing:
B* B_instance = new B();
B_instance[some_int]->some_field_from_A;
the errors are:
error C2819: type 'B' does not have an overloaded member 'operator ->'
error C2039: 'some_field_from_A' : is not a member of 'B'
an why do I need to have -> operator overloading and how it should looks like? It doesn't make sense to me.
I am using Visual Studio 2012.
Bas a pointer? It doesn't look like a vector of pointers is really necessary, either.Bbecause pointers can be indexed like arrays.