具有[]运算符超载的模板类
Template class with [] operator overloading
i使用模板类
template <class T>
class Array
{
enum {size = 10};
T A[size];
public:
T& operator [] (int index)
{
return A[index];
}
};
一切正常。我想知道如何从我的程序中调用[]操作员?
operator[]
可以像任何其他方法一样称呼: myArray.operator[](3) = 5
或使用普通数组语法: myArray[3] = 5
。当这种方式称为时,括号中的值是函数的参数。
相关文章:
- 虚拟超载运算符>>和<<
- 为什么我的超载"+"运算符返回的总额错误?
- 我可以防止与null与超载运算符==进行比较
- 超载 运算符添加const char
- 是否有一种方法可以在超载运算符函数中接触默认运算符函数
- 堆上的模板类超载运算符
- 我想将超载运算符添加到派生类中
- 超载 *运算符时无法转换错误
- 在将对象声明为挥发性时,如何在C 中超载运算符
- 超载运算符*与操作员双重模棱两可()
- 在C 中的超载运算符中使用局部变量
- 如何使用超载 运算符组合两个链接列表
- C 超载 运算符,因此您可以在该类中添加不同的类并获得第三类
- 超载运算符== C 时获取SigSeGV(分割故障)
- 超载运算符=在单链接列表中
- 超载 运算符在C 中加入两个字符串(一些疑问)
- 使用超载运算符添加构造函数
- 为什么在C 中调用模板超载运算符时,我会遇到细分故障
- 是否可以超载[]运算符在不定义类的情况下访问特定的字符
- 没有可行的超载运算符[]