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 

Re: Funktion "nachtr344glich" implemen...^

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





PostPosted: Thu Jun 16, 2005 10:16 am    Post subject: Re: Funktion "nachtr344glich" implemen...^ Reply with quote




"Mark Henning" <mh (AT) homolog (DOT) de> schrieb im Newsbeitrag
news:e542b114fl3a9lf049h01mdmhlj58ioflm (AT) 4ax (DOT) com...
Quote:
- Die neuen Funktionen sollen genau wie die Standard-Funktionen von
std::string aus aufrufbar sein. Ich hätte also gerne sowas wie:
std::string str("abcdef...");
str = str.right(2);

Das geht nicht. right ist kein Member von std::string und es gibt auch keine
Möglichkeit sie dazu zu machen (jedenfalls nicht ohne die Header zu
manipulieren. Aber niemand hindert dich daran, deine eigene Klasse zu
implementieren, die sich weitestgehend wie std::string verhält und
zusätzlich die von dir gewünschten Eigenschaften hat:

class MyString: public std::string
{
public:
MyString right(size_t count) const
{
return substr(length() - 2);
}
...
};

Und bevor jetzt jemand schreit, dass man von std::string nicht ableiten
darf... Man darf, wenn man weiß, was man tut und die Konsequenzen kennt (und
inKauf nimmt). Man muss dann allerdings etwas denken und das ist
anstrengender als einen virtuellen Destruktor zu suchen.

HTH
Heinz

--
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.