【发布时间】:2014-12-31 11:03:57
【问题描述】:
假设我们有一个类:
class A {
private:
int index;
public:
// related overloaded functions and other stuffs
};
现在说我们将它用作数组中需要 int 的索引。
A in;
Z z = arr[in]; // arr is of some type Z.
我想问一下'in'什么时候用'in',这里调用了什么函数(比如拷贝构造函数或者重载赋值运算符)或者对象是直接typecast的。
如果类是这样的会有什么不同
class A {
private:
int index1;
int index2;
public:
// related overloaded functions and other stuffs
};
【问题讨论】:
-
请贴出
A的完整定义。它可能有一个整数类型的转换运算符吗? -
no 我没有做任何转换操作。只是赋值运算符和复制构造函数。我什至不知道转换运算符。
-
如果没有转换运算符,这甚至不应该编译,如果您有编译示例,请将其发布为sscce.org。
标签: c++ arrays class operator-overloading