I'm trying to preform a Deep Copy of one class to another. Using VS2015.
below on *(clsOriginalToCopy + lngIndex); is where I get the error, I am at a loss.
for (lngIndex = 0; lngIndex < lngSize; lngIndex += 1)
{
*(this + lngIndex) = *(clsOriginalToCopy + lngIndex);
}
edit
Error C2784 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(std::basic_string<_Elem,_Traits,_Alloc> &&,const _Elem)': could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &&' from 'const CResizableArray' Homework 8 - DeepCopy 479
edit
MCVE. It wants me to add more details so enjoy this excerpt from
"Hitchhikers guide to the galaxy"
“For instance, on the planet Earth, man had always assumed that he was more intelligent than dolphins because he had achieved so much—the wheel, New York, wars and so on—whilst all the dolphins had ever done was muck about in the water having a good time. But conversely, the dolphins had always believed that they were far more intelligent than man—for precisely the same reasons.” ― Douglas Adams, The Hitchhiker's Guide to the Galaxy
CResizableArray::CResizableArray()
{
Initialize(0, 0);
}
CResizableArray::CResizableArray(long lngSize)
{
Initialize(lngSize, 0);
}
CResizableArray::CResizableArray(long lngSize, long lngValue)
{
Initialize(lngSize, lngValue);
}
void CResizableArray::Initialize(long lngSize, long lngValue)
{
m_lngArraySize = 0;
m_palngValues = 0;
SetSize(lngSize, lngValue);
}
void CResizableArray::operator = (const CResizableArray &clsOriginalToCopy)
{
if (this != &clsOriginalToCopy)
{
CleanUp();
DeepCopy(clsOriginalToCopy);
}
}
CResizableArray::~CResizableArray()
{
CleanUp();
}
void CResizableArray::CleanUp()
{
SetSize(0, 0);
}
void CResizableArray::SetSize(long lngNewSize)
{
SetSize(lngNewSize, 0);
}
void CResizableArray::SetSize(long lngNewSize, long lngValue)
{
long* palngNewValues = 0;
long lngIndex = 0;
long lngStop = 0;
if (lngNewSize < 0) lngNewSize = 0;
if (lngNewSize > 100000) lngNewSize = 100000;
palngNewValues = new long[lngNewSize];
for (lngIndex = 0; lngIndex < lngStop; lngIndex += 1)
{
*(palngNewValues + lngIndex) = lngValue;
}
if (lngNewSize < m_lngArraySize) lngStop = lngNewSize;
else lngStop = m_lngArraySize;
for (lngIndex = 0; lngIndex < lngStop; lngIndex += 1)
{
*(palngNewValues + lngIndex) = *(m_palngValues + lngIndex);
}
if (m_palngValues != 0)
{
delete[] m_palngValues;
m_palngValues = 0;
}
m_palngValues = palngNewValues;
m_lngArraySize = lngNewSize;
}
void CResizableArray::DeepCopy(const CResizableArray &clsOriginalToCopy)
{
long lngSize = 0;
long lngIndex = 0;
lngSize = clsOriginalToCopy.GetSize();
SetSize(lngSize);
for (lngIndex = 0; lngIndex < lngSize; lngIndex += 1)
{
*(this + lngIndex) = *(clsOriginalToCopy + lngIndex);
}
}
reply from instructor
The "this" key word is a pointer to the current active instance, which in this case is an instance of CResizableArray.
You have "this + lngIndex" which is trying to add an integer to it. That would make sense if you had an array of instances and you want to jump to an instance with an index further down the list. But you don't have an array of instances. You have an instances which happens to have an array inside of it.
So, you are trying to move up and down outside of the class. What you really want to do is move up and down inside of the class.
reply from instructor