Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Override a virtual member in a instance?

Reply
Thread Tools

Override a virtual member in a instance?

 
 
tony@donotspamme.ar
Guest
Posts: n/a
 
      08-24-2006

Hi!
A derived class can override a method in the base class it inherits for,
and even my dog knows that. More incredibly, I know and understand it
too.

But, can a (of course virtual in this case) method be overriden in an
instance instead? For example, to provide some callbacks to a class.

Should I use virtual functions instead? How do I pass the this pointer
when casting it from or to in any useful way seems to break every C++
language rule? As a normal parameter? But then it doesn't really look
so OOP anymore.

Thanks a lot,
Tony

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-24-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> A derived class can override a method in the base class it inherits
> for, and even my dog knows that. More incredibly, I know and
> understand it too.
>
> But, can a (of course virtual in this case) method be overriden in an
> instance instead? For example, to provide some callbacks to a class.


No. For that you usually store pointers to [member] functions and assign
them different values based on the need, per instance.

> Should I use virtual functions instead?


Instead of what? Instead of virtual functions? Uh... Yes!.. I mean,
no... I mean... Could you rephrase, please?

> How do I pass the this pointer
> when casting it from or to in any useful way seems to break every C++
> language rule? As a normal parameter? But then it doesn't really look
> so OOP anymore.


Huh? I think I don't understand (where does it place me relative to
your dog?), could you give an example in C++?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      08-24-2006
(E-Mail Removed) wrote:

>
> Hi!
> A derived class can override a method in the base class it inherits for,
> and even my dog knows that. More incredibly, I know and understand it
> too.
>
> But, can a (of course virtual in this case) method be overriden in an
> instance instead? For example, to provide some callbacks to a class.
>
> Should I use virtual functions instead? How do I pass the this pointer
> when casting it from or to in any useful way seems to break every C++
> language rule? As a normal parameter? But then it doesn't really look
> so OOP anymore.


Virtual functions are type bound (although to the dynamic type). You can use
a function pointer or a member variable whose type is a function object if
you want to override the semantics of the call per instance.



Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
non-virtual call to a virtual function using pointer to member archimed7592 C++ 4 05-30-2007 08:59 PM
virtual vs pure virtual member function sam_cit@yahoo.co.in C++ 7 05-02-2007 10:00 AM
same overhead in calling virtual and non virtual member function...? ypjofficial@indiatimes.com C++ 11 09-10-2006 06:08 PM
Override virtual member functions in Subclasses Ruben Van Havermaet C++ 22 08-04-2004 02:58 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM



Advertisments