Click here to Skip to main content
15,914,452 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WritePrinter API seems Good but Behave Difficult Pin
David Crow28-Oct-05 2:15
David Crow28-Oct-05 2:15 
Question(const char*)this == this Pin
WernerPos26-Oct-05 23:58
WernerPos26-Oct-05 23:58 
AnswerRe: (const char*)this == this Pin
cmk27-Oct-05 0:44
cmk27-Oct-05 0:44 
GeneralRe: (const char*)this == this Pin
WernerPos27-Oct-05 1:18
WernerPos27-Oct-05 1:18 
GeneralRe: (const char*)this == this Pin
WernerPos27-Oct-05 1:26
WernerPos27-Oct-05 1:26 
GeneralRe: (const char*)this == this Pin
cmk27-Oct-05 2:02
cmk27-Oct-05 2:02 
GeneralRe: (const char*)this == this Pin
WernerP27-Oct-05 22:11
WernerP27-Oct-05 22:11 
AnswerRe: (const char*)this == this Pin
BadKarma27-Oct-05 1:41
BadKarma27-Oct-05 1:41 
Hi,

I think you made an error in your constructors.

WernerPos wrote:
String(String & toCopy):m_szValue(new char[toCopy.length()]) {strcpy(m_szValue, (const char*)toCopy);}
String(char const * const szValue):m_szValue(new char[strlen(szValue)+1]) {strcpy(m_szValue, szValue);};


you didn't forget to allocate space for the ending 0, but did forget to initialize it.
String(String & toCopy): m_szValue(new char[toCopy.length() + 1]) 
{
 strcpy(m_szValue, (const char*)toCopy);
 m_szValue[toCopy.length()] = 0;
}
String(char const * const szValue):m_szValue(new char[strlen(szValue)+1]) 
{
 strcpy(m_szValue, szValue);
 m_szValue[strlen(szValue)] = 0;
};


This causes to have a wrong result for
size_t length() {return strlen(m_szValue);}
because strlen gives the number of chars until the first '\0'.
bool operator== (String const & toCompare) const {return 0 == strcmp( (const char*)this, (const char*)toCompare ); };<br />
bool operator> (String const & toCompare) const {return 0 > strcmp( (const char*)this, (const char*)toCompare ); };<br />
bool operator< (String const & toCompare) const {return 0 < strcmp( (const<br />
 char*)this, (const char*)toCompare ); };<br />

because strcmp alsoo requires the ending '\0' to compare the strings or which is greater or not.

Regards Kurt



codito ergo sum
AnswerRe: (const char*)this == this Pin
BadKarma27-Oct-05 2:34
BadKarma27-Oct-05 2:34 
GeneralRe: (const char*)this == this Pin
WernerP27-Oct-05 22:19
WernerP27-Oct-05 22:19 
GeneralRe: (const char*)this == this Pin
WernerP27-Oct-05 2:42
WernerP27-Oct-05 2:42 
QuestionSwitch views inside ChildFrm Pin
LiYS26-Oct-05 22:38
LiYS26-Oct-05 22:38 
QuestionTruncation Pin
Raza568026-Oct-05 22:33
Raza568026-Oct-05 22:33 
AnswerRe: Truncation Pin
Cedric Moonen26-Oct-05 22:41
Cedric Moonen26-Oct-05 22:41 
AnswerRe: Truncation Pin
kakan27-Oct-05 0:51
professionalkakan27-Oct-05 0:51 
QuestionXp Like ScrollBar in VC++ 6.0 Pin
Neagoe Gabriel26-Oct-05 22:19
Neagoe Gabriel26-Oct-05 22:19 
AnswerRe: Xp Like ScrollBar in VC++ 6.0 Pin
Anonymous27-Oct-05 0:01
Anonymous27-Oct-05 0:01 
Questionwincrypt.h? Pin
adonisv26-Oct-05 20:32
adonisv26-Oct-05 20:32 
AnswerRe: wincrypt.h? Pin
__yb26-Oct-05 21:30
__yb26-Oct-05 21:30 
GeneralRe: wincrypt.h? Pin
adonisv27-Oct-05 12:08
adonisv27-Oct-05 12:08 
GeneralRe: wincrypt.h? Pin
TheGreatAndPowerfulOz28-Oct-05 3:21
TheGreatAndPowerfulOz28-Oct-05 3:21 
GeneralRe: wincrypt.h? Pin
adonisv28-Oct-05 13:46
adonisv28-Oct-05 13:46 
GeneralRe: wincrypt.h? Pin
__yb31-Oct-05 21:10
__yb31-Oct-05 21:10 
Questiona garbage value from va_arg() Pin
plowstar26-Oct-05 19:29
plowstar26-Oct-05 19:29 
AnswerRe: a garbage value from va_arg() Pin
__yb26-Oct-05 21:43
__yb26-Oct-05 21:43 

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.