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 

Nur konstante Funktionen einer Basisklass e öffentlich mache

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





PostPosted: Fri May 11, 2007 2:16 pm    Post subject: Nur konstante Funktionen einer Basisklass e öffentlich mache Reply with quote



Hallo,

gibt es eine Möglichkeit nur die konstanten Funktionen/Eigenschaften
einer Basisklasse öffentlich zu machen?

Also sowas in der Art:

class myclass : protected std::string
{
public:
operator const string&() { return *this; } // ist natürlich Blödsinn

myclass& operator=(const myclass& r);
};


myclass inst1, inst2;

// erlaubt soll sein...
std::string str = inst1;
void foo(const std::string&);
foo(inst1);
std::string::const_iterator i = inst.begin();
inst1 = inst2; // Der Operator ist in myclass definiert

// nicht erlaubt hingegen
inst += "abc";
std::string::iterator i = inst.begin();

Ich kann natürlich sämtliche konstanten Funktionen per using freigeben,
aber das ist erstens Kinderarbeit und zweitens erzeugt es natürlich sehr
tiefe Abhängigkeiten zu den Methoden der Basisklasse. Wenn sich
Überladene Methoden in der const-Eigenschaft unterscheiden (z.B.
std::string::begin) geht das auch nicht. Außerdem bekomme ich damit die
implizite Konvertierung in ein konstantes Objekt vom Typ string nicht hin..


Marcel
Back to top
Thomas Maeder
Guest





PostPosted: Fri May 11, 2007 9:28 pm    Post subject: Re: Nur konstante Funktionen einer Basisklasse öffentlich ma Reply with quote



Marcel Müller <news.5.maazl (AT) spamgourmet (DOT) org> writes:

Quote:
gibt es eine Möglichkeit nur die konstanten Funktionen/Eigenschaften
einer Basisklasse öffentlich zu machen?

Also sowas in der Art:

class myclass : protected std::string

Hmm. std::string wurde nicht geschaffen, um als (nicht-private)
Basisklasse zu dienen.

Quote:
{
public:
operator const string&() { return *this; } // ist natürlich Blödsinn

Was hälst Du von

std::string const &asString() const;

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