Hmm, I didn't make this an MFC project per se, just started with an empty solution but I guess some MFC is still being put it automatically. That link was rather helpful, shows the same error message I'm getting so that should be the right track. I'm not using strcpy
or strncpy
anywhere. I use my own loops to copy element by element in CABLE. In fact the only string
function I think I'm using is strlen
. Here's the CABLE class in it's entirty. It's pretty simplistic, I'm pretty much just doing it for practice with plans to add on to it as I learn more.
#include CABLE::CABLE()
{
cable = new char[1];
cable[0] = '\0';
length = 0;
}
//Private constructor, used only to create a temp CABLE of set size that is NULL filled.
CABLE::CABLE( int newLength )
{
cable = new char[newLength+1];
length = newLength;
for( int i = 0; i <= length; ++i )
{
cable[i] = '\0';
}
}
CABLE::CABLE( const char * const newCable )
{
length = strlen( newCable );
cable = new char [length+1];
for( int i = 0; i <= length; ++i )
{
cable[i] = newCable[i];
}
cable[length] = '\0';
}
CABLE::CABLE( const CABLE & rhs )
{
length = rhs.GetLength();
cable = new char[length+1];
for( int i = 0; i <= length; ++i )
{
cable[i] = rhs[i];
}
cable[length] = '\0';
}
CABLE::~CABLE()
{
delete cable;
cable = NULL;
length = 0;
}
CABLE & CABLE::operator=( const CABLE & rhs )
{
if ( this != &rhs )
{
delete [] cable;
length = rhs.GetLength();
cable = new char[length+1];
for( int i = 0; i <= length; ++i )
{
cable[i] = rhs[i];
}
cable[length] = '\0';
}
return \*this;
}
char & CABLE::operator[]( int offset )
{
if ( offset > length )
{
return cable[length-1];
}
else
{
return cable[offset];
}
}
char CABLE::operator[]( int offset ) const
{
if ( offset > length )
{
return cable[length-1];
}
else
{
return cable[offset];
}
}
CABLE CABLE::operator+( const CABLE & rhs )
{
int totalLength = length + rhs.GetLength();
CABLE temp( totalLength );
for( int i = 0; i < length; ++i )
{
temp[i] = cable[i];
}
for( int j = 0; j < rhs.GetLength(); ++j, ++i )
{
temp[i] = rhs[j];
}
temp[totalLength] = '\0';
return temp;
}
void CABLE::operator+=( const CABLE & rhs )
{
int totalLength = length + rhs.GetLength();
CABLE temp( totalLength );
for( int i = 0; i < length; ++i )
{
temp[i] = cable[i];
}
for( int j = 0;