Click here to Skip to main content
16,004,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to store the unrecognized characters in VC6.0+ADO+sql server2000 Pin
yuyi200331-Jul-04 22:45
yuyi200331-Jul-04 22:45 
GeneralPipes read handle Pin
Mohammed Saleem30-Jul-04 22:09
Mohammed Saleem30-Jul-04 22:09 
GeneralMSDN Says... Pin
bikram singh31-Jul-04 15:53
bikram singh31-Jul-04 15:53 
Generaloperator+, problems... Pin
Sheff30-Jul-04 21:06
Sheff30-Jul-04 21:06 
GeneralRe: operator+, problems... Pin
peterchen30-Jul-04 22:59
peterchen30-Jul-04 22:59 
GeneralRe: operator+, problems... Pin
Sheff30-Jul-04 23:03
Sheff30-Jul-04 23:03 
GeneralRe: operator+, problems... Pin
Sheff30-Jul-04 23:22
Sheff30-Jul-04 23:22 
GeneralRe: operator+, problems... Pin
peterchen31-Jul-04 0:22
peterchen31-Jul-04 0:22 
So my first idea was right - the class has no corfrect copy CTor Wink | ;)

OK, here's what happens:

when you do return temp, the compiler returns a copy of temp, and calls the destructor of temp (which deletes temp.buffer).

For the copy, C++ looks for a copy constructor with the signature CStr(CStr const &). Since you didn't specify a copy constructor, C++ generates a default one, which makes a "flat" copy (the .buffer member of the copy is pointing to the same buffer as temp.buffer, which is deleted in temp's destructor)

Provide a correct copy constructoir (similar to CStr(char const *), but using a CStr const & as argument), it will work.
---------------------
Some more notes:

The behavior of a CStr object passed to printf() (or any other variable argument function) is not defined by the C++ standard. It works on Microsoft Visual C++ (and some MFC code relies on this), but it is not portable.

You might want to get a C++ book to learn a bit more about what is necessary to create a "correctly behaving" class, which elements are created by default, etc.

Writing a CStr class is an interesting practice, and might be useful if you working on a "no dependency mini exe" Project. However, there are so many reliable string class implementations out there that it rarely makes sense.
First there is std::string. Yes, it's ugly, compiler errors (if you do something wrong) are indecipherable, and the VC6 MSDN documentation for it is useless - but it works, it's portable, it's the standard.
Second, MFC's "less scientific" but widely successful CString class is available outside of MFC projects as well (on VC7, it's part of the ATL/MFC libraries, on VC6 you can use the semi-official WTL::CString clone, or any other CString clone you find on the internet)

good luck!




we are here to help each other get through this thing, whatever it is Vonnegut jr.

sighist || Agile Programming | doxygen

GeneralRe: operator+, problems... Pin
Sheff31-Jul-04 0:46
Sheff31-Jul-04 0:46 
GeneralAccelerator keys Pin
Gammill30-Jul-04 19:42
Gammill30-Jul-04 19:42 
GeneralCombobox data transfer Pin
Puah30-Jul-04 19:35
Puah30-Jul-04 19:35 
GeneralRe: Combobox data transfer Pin
Jaime Stuardo31-Jul-04 5:03
Jaime Stuardo31-Jul-04 5:03 
GeneralCString & hex conversion problem Pin
lyn30-Jul-04 19:17
lyn30-Jul-04 19:17 
GeneralRe: CString & hex conversion problem Pin
Gammill30-Jul-04 19:32
Gammill30-Jul-04 19:32 
GeneralRe: CString & hex conversion problem Pin
lyn30-Jul-04 20:21
lyn30-Jul-04 20:21 
Questionhow to iternate and remove content from CMap at the same loop? Pin
zecodela30-Jul-04 18:31
zecodela30-Jul-04 18:31 
AnswerRe: how to iternate and remove content from CMap at the same loop? Pin
Gammill31-Jul-04 7:03
Gammill31-Jul-04 7:03 
AnswerWild guess on CMapStringtoPtr key removal Pin
bikram singh31-Jul-04 16:50
bikram singh31-Jul-04 16:50 
GeneralRe: Wild guess on CMapStringtoPtr key removal Pin
zecodelathe2nd31-Jul-04 17:25
zecodelathe2nd31-Jul-04 17:25 
GeneralThread Static calling non-static function Pin
Danny Gilbert30-Jul-04 17:43
Danny Gilbert30-Jul-04 17:43 
GeneralRe: Thread Static calling non-static function Pin
bikram singh31-Jul-04 16:10
bikram singh31-Jul-04 16:10 
Generalftp server Pin
Ryan McDermott30-Jul-04 16:21
Ryan McDermott30-Jul-04 16:21 
GeneralLoading Variable in EditBox Pin
arunforce30-Jul-04 12:00
arunforce30-Jul-04 12:00 
GeneralRe: Loading Variable in EditBox Pin
Archer28230-Jul-04 12:57
Archer28230-Jul-04 12:57 
GeneralRe: Loading Variable in EditBox Pin
arunforce30-Jul-04 13:13
arunforce30-Jul-04 13:13 

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.