有一類這樣的:運營商[]重載
class X {
public:
...
private:
int changeable[3];
int unchangeable[3];
};
這是其理想的用法:
X x;
x[0] = 1; // here changeable[0] should be used
a = x[0]; // here unchangeable[0] should be used
是否有限定class X
operator[]
以實施的方法嗎?
您可以實現第一種情況下,可以實現第二種情況但不能兩者一起 – Gaim 2010-09-30 21:24:01
他可以重載運營商,它可能會選擇基於上下文。 – JSchlather 2010-09-30 21:26:58