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 

Multiple Inheritance

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





PostPosted: Thu May 06, 2004 9:16 am    Post subject: Multiple Inheritance Reply with quote



Hi,

folgendes Beispiel:

class A { public: virtual int f(); };
class B { public: virtual double f(); };

Gibt es eine Moeglichkeit von A und B gleichzeitig abzuleiten und gezielt
ein f() (oder beide) zu ueberschreiben?
Also z.B.

class AB : public A, public B { public: int f(); };

Der Compiler (MS VC.NET) motzt (zu recht Wink, dass sich AB::f() von B::f()
nur im Rueckgabewert unterscheidet.
Gibt es eine spezielle Syntax oder ist das eine Luecke von C++?

Danke & Gruss, Stephan

--
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
Markus Breuer
Guest





PostPosted: Thu May 06, 2004 9:35 am    Post subject: Re: Multiple Inheritance Reply with quote



Quote:
class A { public: virtual int f(); };
class B { public: virtual double f(); };

Gibt es eine Moeglichkeit von A und B gleichzeitig abzuleiten und gezielt
ein f() (oder beide) zu ueberschreiben?
Also z.B.

class AB : public A, public B { public: int f(); };

Hast du es einmal mit

class AB : public A, public B { public: int A::f(); };

probiert?

Gruß Maruks

--
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
Stephan Keil
Guest





PostPosted: Thu May 06, 2004 10:33 am    Post subject: Re: Multiple Inheritance Reply with quote



Quote:
Hast du es einmal mit

class AB : public A, public B { public: int A::f(); };

probiert?

Dem Compiler gefaellt das nicht :-(

error C3240: 'f' : must be a non-overloaded pure virtual member function of
'A'
error C2838: 'f' : illegal qualified name in member declaration
An explicit override can only be used for a method that was first
introduced in an interface and whose override qualifier is an interface
error C2555: 'AB::f': overriding virtual function return type differs and
is not covariant from 'B::f'

Sollte das denn funktionieren?

Stephan

--
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
Helmut Zeisel
Guest





PostPosted: Thu May 06, 2004 10:59 am    Post subject: Re: Multiple Inheritance Reply with quote

Stephan Keil wrote:
Quote:
Hast du es einmal mit

class AB : public A, public B { public: int A::f(); };

probiert?

Sollte das denn funktionieren?

Nein, die Lösung findest Du in D&E, Chapter 12.8:

class A1
{
virtual int A_f() {return A::f();}
}

Dann von A1 statt von A ableiten und A_f ueberschreiben

Helmut

--
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
Stephan Keil
Guest





PostPosted: Thu May 06, 2004 12:40 pm    Post subject: Re: Multiple Inheritance Reply with quote

Quote:
Nein, die Lösung findest Du in D&E, Chapter 12.8:

class A1
{
virtual int A_f() {return A::f();}
}

Dann von A1 statt von A ableiten und A_f ueberschreiben

Hm, damit habe ich aber nicht A::f() ueberschrieben:
AB ab;
A* a = &ab;
a->f(); // hier wird A::f() aufgerufen, ich moechte aber AB::f()
aufrufen

Also doch keine Loesung :(

--
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
Helmut Zeisel
Guest





PostPosted: Thu May 06, 2004 12:55 pm    Post subject: Re: Multiple Inheritance Reply with quote

Stephan Keil wrote:

Quote:
Nein, die Lösung findest Du in D&E, Chapter 12.8:

class A1
{
virtual int A_f() {return A::f();}
}

Dann von A1 statt von A ableiten und A_f ueberschreiben


Hm, damit habe ich aber nicht A::f() ueberschrieben:
AB ab;
A* a = &ab;
a->f(); // hier wird A::f() aufgerufen, ich moechte aber AB::f()
aufrufen

Also doch keine Loesung Sad

Hast recht, ich war zu schlampig beim Abschreiben; richtig ist

class A1: public A
{
virtual int A_f() = 0;
virtual int f(){ return A_f();}
};

Wenn Du jetzt AB von A1 ableitest und A_f ueberschreibst, ruft Dein
a->f() wirklich A_f() auf.

Helmut

--
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
Helmut Zeisel
Guest





PostPosted: Thu May 06, 2004 1:01 pm    Post subject: Re: Multiple Inheritance Reply with quote

Helmut Zeisel wrote:


Quote:
Nein, die Lösung findest Du in D&E, Chapter 12.8:

PS: http://www.geocrawler.com/archives/3/362/1996/11/0/2039291/

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