C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Seltsames Problem beim 334berladenen Operatorn^

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Martin Bauer
Guest





PostPosted: Tue Mar 29, 2005 11:35 am    Post subject: Seltsames Problem beim 334berladenen Operatorn^ Reply with quote



hallo,

ich habe eine Klasse CTChar als Feldtyp für eine DBF-Tabelle, daher keine
gewöhnliche String-Klasse.

Ich setze den Wert zurück in dem ich
pvit->m_cWert1 = "";
aufrufe. m_cWert1 ist eine Instanz von CTChar, der Operator sieht so aus:

CTChar& CTChar::operator = (const char* s)
{
memset(value, 0, size);
strncpy(value, s, size);
return *this;
}

Das verrückte ist, wenn ich im Debugger geobachte was für s ankommt stehen
da binäre 4´ren drinne.

Wenn ich jedoch
pvit->m_cWert1 = "Test";
oder
pvit->m_cWert1 = " "; // Leerzeichen vor '
verwende funktioniert der Operator.

wenn ich
pvit->m_cWert1 = '';
verwende, kracht es zwar bei strncpy, aber der Wert von s stimmt schon mal.

Kann mir geholfen werden ?
Vielen Dank.

MfG
Martin Bauer

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
Thomas Maeder
Guest





PostPosted: Tue Mar 29, 2005 4:27 pm    Post subject: Re: Seltsames Problem beim Überladenen Operator Reply with quote



"Martin Bauer" <xy (AT) ungeloest (DOT) de> writes:

Quote:
ich habe eine Klasse CTChar als Feldtyp für eine DBF-Tabelle, daher keine
gewöhnliche String-Klasse.

[usw.]

Poste bitte das minimale übersetz- und ausführbre Programm, welches
dieses Verhalten hat.

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Daniel Schüle
Guest





PostPosted: Tue Mar 29, 2005 4:37 pm    Post subject: Re: Seltsames Problem beim Überladenen Operator Reply with quote



Hallo

Quote:
CTChar& CTChar::operator = (const char* s)
{
memset(value, 0, size);
strncpy(value, s, size);
return *this;
}

was spricht gegen

CTChar& CTChar::operator = (const char* s)
{
memset(value, 0, size);
if(s)
strncpy(value, s, size);
return *this;
}

und dann

pvit->m_cWert1 = '';
pvit->m_cWert1 = 0;



pvit->m_cWert1 = "";
ist ein Stringliteral und damit ein "const char *", damit ist es eine
Adresse
Auf dieser Adresse ist ein ASCII Nullzeichen abgelegt
(0x30 wenn ich mich nicht täusche)

wenn Du
pvit->m_cWert1 = '';
schreibest, dann setzst du diese Adresse explizit auf 0
Was die Bedeutung hat, "dieser Zeiger darf nicht dereferenziert werden"

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Horst Kraemer
Guest





PostPosted: Wed Mar 30, 2005 7:13 am    Post subject: Re: Seltsames Problem beim 334berladenen Operatorn^ Reply with quote

"Martin Bauer" <xy (AT) ungeloest (DOT) de> wrote:

Quote:
hallo,

ich habe eine Klasse CTChar als Feldtyp für eine DBF-Tabelle, daher keine
gewöhnliche String-Klasse.

Ich setze den Wert zurück in dem ich
pvit->m_cWert1 = "";

Was passiert bei

pvit->m_cWert1 = "";

???

--
Horst

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.