For some reason I cannot add comment to my prewious answer so I am submitting a new answe:
the "property" extension is specific to Visual C++ from version 6. there is simmilar extension in Borland C++ Builder and Borland ObjectPascal - the sintax is different but the behavior is the same. All this extensiona are compiler dependant and they translate to substituting the "." operator with a call to the get or set function. In C++ you cannot overload ".". That is why I do not think it is possible to implement this in standard C++.
As for the second part of your comment:
"const" function is a function that does not change any of the class members and can call only "const" function. You can operload operator[] like that, but it will not ser your goals, or at least not directly. Look at the following code example and comments:
class B
{
public:
};
class A
{
B m_b; // using this just to have some return value available
public:
const B& operator[](int i) const { return m_b; }
B& operator[](int i){ return m_b; }
};
int main(int argc, char* argv[])
{
A a;
A const & a1 = a;
B b;
// the non const version of "operator[]" will be used as "a" is not constant.
a[4] = b;
B const & d = a[4];
// the const version of "operator[]" will be used as a1 is a const&
B const & c = a1[4]; // as a1 is "const&" the const version of operator[] will be used
// but it is possible to do this
// we convert "a" to a const& so we force the "operator[]() const" to be used.
// but i am not sure that this is what you want to do
B const & e = ((A const&)a)[4];
return 0;
}
In any case I will recommend to abenden the idea of overloading operator []. Instead implement "get" and "set" methods that deliver the reqiored functionality. This way you will avoid the confusion the overloaded [] will bring to the users of your classes.