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 

calling overloaded methode

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





PostPosted: Wed May 10, 2006 9:39 am    Post subject: calling overloaded methode Reply with quote



<code>
class A
{
public:
A ();
virtual void InitControls ();
};

A::A ()
{ InitControls(); }

void A::InitControls ()
{}

class B : public A
{
public:
virtual void InitControls();
};

void B::InitControls ()
{
// do something
}
</code>

Der Aufruf von InitControls im ctor von A landet in A::InitControls().
Aber die Methode ist doch virtuel und sollte daher in B::InitControls()
landen? Wie schafe ich es, das der Aufruf in A::A() in einer abgleiteten
Klasse davon landet?

--
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: Fri May 12, 2006 4:22 pm    Post subject: Re: calling overloaded methode Reply with quote



Christian Buhtz <yspam (AT) gmx (DOT) net> writes:



Vorbemerkung: In Deiner Frage geht's nicht ums Überladen

(overloading), sondern ums Überschreiben (over*riding*).



Quote:
code

class A

{

public:

A ();

virtual void InitControls ();

};



A::A ()

{ InitControls(); }



void A::InitControls ()

{}



class B : public A

{

public:

virtual void InitControls();

};



void B::InitControls ()

{

// do something

}

/code



Der Aufruf von InitControls im ctor von A landet in A::InitControls().

Aber die Methode ist doch virtuel und sollte daher in B::InitControls()

landen?



Nein. Zum Zeitpunkt der Ausführung des Konstruktos der Klasse ist der

dynamische Typ des in Konstruktion begriffenen Objekts A; deshalb wird

A::InitControls() aufgerufen.





Quote:
Wie schafe ich es, das der Aufruf in A::A() in einer abgleiteten

Klasse davon landet?



Zum Glück gar nicht. Die Datenmember, welche durch die Klasse B

deklariert werden, sind ja noch gar nicht initialisiert zu diesem

Zeitpunkt.


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