Click here to Skip to main content
15,916,318 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Include Help Needed Pin
Steen Krogsgaard10-Mar-05 1:25
Steen Krogsgaard10-Mar-05 1:25 
GeneralRe: Include Help Needed Pin
Jeryth10-Mar-05 5:18
Jeryth10-Mar-05 5:18 
GeneralRe: Include Help Needed Pin
Steen Krogsgaard10-Mar-05 5:27
Steen Krogsgaard10-Mar-05 5:27 
GeneralRe: Include Help Needed Pin
Jeryth10-Mar-05 6:11
Jeryth10-Mar-05 6:11 
GeneralRe: Include Help Needed Pin
Steen Krogsgaard 210-Mar-05 7:34
Steen Krogsgaard 210-Mar-05 7:34 
GeneralRe: Include Help Needed Pin
Jeryth14-Mar-05 5:50
Jeryth14-Mar-05 5:50 
GeneralRe: Include Help Needed Pin
Steen Krogsgaard 214-Mar-05 9:32
Steen Krogsgaard 214-Mar-05 9:32 
GeneralRe: Include Help Needed Pin
Jeryth14-Mar-05 17:29
Jeryth14-Mar-05 17:29 
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.h>

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; j < rhs.GetLength(); ++j, ++i )
	{
		temp[i] = rhs[j];
	}
	temp[totalLength] = '\0';

	*this = temp;
}

bool CABLE::operator==( const CABLE & rhs ) const
{
	if ( length != rhs.length )
		return false;

	for( int i = 0; i < length; ++i )
	{
		if ( cable[i] != rhs.cable[i] )
			return false;
	}
	return true;
}

const char * CABLE::GetCable() const
{
	return cable;
}

int CABLE::GetLength() const
{
	return length;
}


So as it is, I'm barely using the string class at all. It'd almost be worth it to swap out the strlen for a sizeof() call / size of a char.

________________________________________________________________________
The question "Do computers think?" is the same as "Can submarines swim?"
Signature Red Studios

Jeryth

GeneralRe: Include Help Needed Pin
Steen Krogsgaard 217-Mar-05 7:15
Steen Krogsgaard 217-Mar-05 7:15 
GeneralRe: Include Help Needed Pin
Steen Krogsgaard10-Mar-05 1:28
Steen Krogsgaard10-Mar-05 1:28 
GeneralRe: Include Help Needed Pin
Jeryth10-Mar-05 4:40
Jeryth10-Mar-05 4:40 
Generalexecution! Pin
mpapeo9-Mar-05 7:42
mpapeo9-Mar-05 7:42 
GeneralRe: execution! Pin
David Crow9-Mar-05 8:12
David Crow9-Mar-05 8:12 
GeneralRe: execution! Pin
mpapeo9-Mar-05 8:26
mpapeo9-Mar-05 8:26 
GeneralRe: execution! Pin
David Crow9-Mar-05 8:57
David Crow9-Mar-05 8:57 
GeneralRe: execution! Pin
mpapeo9-Mar-05 10:04
mpapeo9-Mar-05 10:04 
GeneralRe: execution! Pin
David Crow9-Mar-05 10:11
David Crow9-Mar-05 10:11 
GeneralRe: execution! Pin
mpapeo9-Mar-05 12:33
mpapeo9-Mar-05 12:33 
GeneralRe: execution! Pin
David Crow10-Mar-05 2:53
David Crow10-Mar-05 2:53 
GeneralRe: execution! Pin
mpapeo10-Mar-05 11:09
mpapeo10-Mar-05 11:09 
GeneralRe: execution! Pin
David Crow10-Mar-05 11:19
David Crow10-Mar-05 11:19 
GeneralRe: execution! Pin
mpapeo10-Mar-05 11:44
mpapeo10-Mar-05 11:44 
GeneralRe: execution! Pin
mpapeo10-Mar-05 14:20
mpapeo10-Mar-05 14:20 
Questioncan VC++ create a MAC version Pin
Mohsen Saad9-Mar-05 7:18
Mohsen Saad9-Mar-05 7:18 
Questioncan VC++ create a MAC version Pin
Mohsen Saad9-Mar-05 7:17
Mohsen Saad9-Mar-05 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.