Hello there~
Well, straight for the problem:
I have a class with a private vector that stores pointers:

class MyClass{
private:
    vector<myOtherCls*> myVector;
public:
//using the following till now:
    vector<myOtherCls*>& getContainer();
};
class myOtherCls{
public:
    void someGetFunc();
};

Now I dont want to use getContainer() but rather he Subscript-Operator.

MyClass cls;
//current call:
cls->getContainer()[i]->someGetFunc();
//but I want to use:
cls[i]->someGetFunc();

With just the []-overload in MyClass it wont work...

public:
//...
    inline myOtherClass*& operator[](unsigned int index){
        return myVector[index];
        //same as:
        //return (*(myVector.begin() + index));
    }
};

When I compile, I get the following errors:
error C2819: type 'MyClass' does not have an overloaded member 'operator ->'
error C2232: '->MyClass::someGetFunc' : left operand has 'class' type, use '.'
error C2039: 'getNode' : is not a member of 'MyClass'

Woah, wall of text.. sorry for that, but I hope someone has an idea to solve teh problem. x.x
Greetz, RF~

It would be better if you just let the overloaded operator work like this

MyClass A;
//initialize A
cout<< A[0].someGetFunc();

Do you know how to accomplish this?

DAMN, I'm so friggin stupid ><
Found the mistake... MyClass* classPtr; Cause I use a Pointer, I'd have to use *classPtr[i] Daaamn :/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.