1

Topic: How to make the overloaded operator [] when a class it is allocated dynamic?

class TElementField
{
public:
int state;
};
class TOperator
{
TElementField Fields [10];
public:
TElementField&operator [] (int index) {
return Fields [index];
}
};
int _tmain (int argc, _TCHAR* argv [])
{
TOperator Operator;
if (Operator [0].state == 1) {
//....
}
TOperator* Operator = new TOperator;
//???
if (Operator [0]-> state == 1) {
//....
}
return _getch ();
}

2

Re: How to make the overloaded operator [] when a class it is allocated dynamic?

gera3323;
Without looking in the code, I will answer: exactly the same as and when the object of a class is allocated .
Implementation should not differ.

3

Re: How to make the overloaded operator [] when a class it is allocated dynamic?

gera3323;
Looking in the code, I will answer that such generally it is impossible. You should at first  the pointer, then cause to the link already access on an index through operator [].
To redefine operator [] for pointers it is impossible, it is forbidden by the standard.

4

Re: How to make the overloaded operator [] when a class it is allocated dynamic?

gera3323 wrote:

if (Operator [0]-> state == 1)
if ((*Operator) [0].state == 1)

5

Re: How to make the overloaded operator [] when a class it is allocated dynamic?

The pointer on something, is such object - the pointer. Or the pointer on ! =