【发布时间】:2018-03-02 03:31:35
【问题描述】:
DynamicArray DynamicArray::operator+(const DynamicArray& rhs) const
{
int count = 0;
int tempCapcacity = mCapacity;
int newCapacity = mCapacity + rhs.mCapacity;
string *temp = allocateAndCopyToNewArray(mWords, mNumWords, newCapacity);
for (int i = tempCapcacity; i < newCapacity; i++)
{
temp[i] = rhs.mWords[count];
count++;
}
return *this;
}
试图让一个重载的运算符组合两个字符串数组。该函数必须是 const 所以我无法更改成员数据。我怎样才能返回这个临时数组?
【问题讨论】:
-
你不能按照现在的代码。您需要创建一个新的
DynamicArray来存储结果并返回。 -
我们不知道
DynamicArray内部...
标签: arrays c++11 operator-overloading this