Do you have a declaration for this in your header file? If you are using the class scope operator :: to define a method outside of a class, it needs to be declared inside the class.
And Peter87 is right. You should actually overload it twice. Once to return a reference, and one to return a const reference.
Ok so I was able to fix the error message stated in my original message. But I have been having trouble later in the program probably due to the fact that I have yet to implement your suggestion.
I dont really understand the reasoning for one returning a reference and one returning a const reference. Thank you.
Returning a reference means that if you change the returned value, you will be changing the actual value stored on the vector, not a copy. And returning a const reference could be thought as a faster version of returning a copy (it's more than that, but to understand it all, you have to learn about references).
You do not have to overload the subscript operator twice. But.........
The reason why you should is because if you ever wanted to call that overloaded subscript operator from a const object, you will need to have it overloaded to return a const data type.
For instance, lets say you overloaded the [ ] for the class Thing.
Check out this code:
1 2 3 4
void PrintSubscript(const Thing& t) {
for (int i = 0; i < t.size(); i++)
cout << t[i] << endl;
}
You would not be able to do this if you only overloaded the subscript operator to return a non-const. You might be able to cast away the const-ness while passing it but that is the type of shit I don't try to take for granted and I'm not sure it would even work anyways. haha
P.S- you also may have to make the overloaded method const itself as well.