在我的图书馆我有一个数组类:级阵列,在运营商投指针[]
template < class Type >
class Array
{
Type* array_cData;
...
Type& operator[] (llint Index)
{
if (Index >= 0 && Index < array_iCount && Exist())
return array_cData[Index];
}
};
这是很好的,但如果我在栈中已经生成的类,如:
Array<NString>* space = new Array<NString>(strList->toArray());
checkup("NString split", (*space)[0] == "Hello" && (*space)[1] == "world");
//I must get the object pointed by space and after use the operator[]
所以我的问题是:我可以得到对象array_cData没有指定对象指出这样的:提前
Array<NString>* space = new Array<NString>(strList->toArray());
checkup("NString split", space[0] == "Hello" && space[1] == "world");
谢谢! :3
-Nobel3D
为什么使用'new'? – Jarod42
当然,只需使用一个自动变量:'Array space(strList-> toArray());'。更好的是使用'std :: array'。 –
user657267
@ Jarod42 strList-> toArray()返回一个数组,我知道它会更好,当函数返回数组 *时,我想到改进-Nobel3D –
Nobel3D