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: Abstrakte Basisklasse über eine Ecke

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





PostPosted: Mon Apr 19, 2004 12:35 am    Post subject: Re: Abstrakte Basisklasse über eine Ecke Reply with quote



Joern P. Meier wrote:

Quote:
Hallo,

in einem aktuellen Projekt trat mit folgendem Code (sinngemäß
nachgestellt) ein Problem auf:

----------------------------------------------------

#include #include #define ___FROB___

Der Name ist reserviert, den darfst du nicht verwenden.

Quote:
using namespace std;

class Foo
{
public:
Foo() { };
virtual ~Foo() { };
virtual void doStuff(int) = 0;
};

class Bar : public Foo
{
public:
Bar() { };
virtual ~Bar() { };
virtual void doStuff(int);
};

void Bar::doStuff(int number)
{
cout << number << endl;
}

class Baz : public Bar
{
public:
Baz() { };
virtual ~Baz() { };
#ifdef ___FROB___
virtual void doStuff(string);
#endif
};

#ifdef ___FROB___
void Baz::doStuff(string text)
{
cout << text << endl;
}
#endif

int main(int argc, char *argv[])
{
Baz baz;
baz.doStuff(12345);
#ifdef ___FROB___
baz.doStuff("Hello");
#endif
}

----------------------------------------------------

Der Compiler (GCC 3.3.3) will dies nicht kompilieren, da er nicht von
int nach const char* konvertieren kann. Ich frage mich nun, was aus
Bar::doStuff(int) geworden ist?

Es ist verdeckt. Sobald du in einer abgeleiteten Klasse eine Funktion
schreibst, werden alle Funktionen mit dem selben Namen aus der
Basisklasse verdeckt. Du mußt ihn explizit mit einem:

using Bar::doStuff;

in Baz "rüberholen".

Quote:
Wenn man ___FROB___ nicht definiert, sieht der Compiler die geerbte
Funktion und meckert nicht mehr.

Richtig, da dann das doStuff aus der Basisklasse nicht mehr verdeckt
wird.

Quote:
Sollte in Baz nicht sowohl Bar::doStuff(int) als auch
Baz::doStuff(string) zur Verfügung stehen?

Nicht ohne das obige "using".

--
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
Rolf Magnus
Guest





PostPosted: Tue Apr 20, 2004 9:07 am    Post subject: Re: Abstrakte Basisklasse über eine Ecke Reply with quote



Joern P. Meier wrote:

Quote:
#define ___FROB___

Der Name ist reserviert, den darfst du nicht verwenden.

In ISO-C++?!

Ja. Alles, was entweder mit einem Underscore gefolgt von einem
Großbuchstaben beginnt oder zwei aufeinanderfolgende Underscores an
beliebiger Stelle enthält, ist reserviert.

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