Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

named override in same class -- is it possible?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Voigt - 30 May 2006 16:51 GMT
I have a function that is called for several distinct reasons.  It is
conceivable that a subclass would want to handle those cases differently.
Therefore, what I want to do is have multiple v-table slots, all pointing to
a common base function.  These functions should be protected, not public.

Here is a short example of what I'm trying to accomplish:

class XYZ
{
protected:
virtual bool SupportsX();
virtual bool SupportsY();
virtual bool SupportsZ();

virtual bool NoSupport() = SupportsX, SupportsY, SupportsZ;
};

bool XYZ::NoSupport( void ) { return false; }

Except that in my case the common default function is considerably more
complicated, and I don't want to repeat the code everywhere.

The compiler gives me:
error C3653: 'SupportsX' : cannot be used as a named override: a function
being overridden not found; did you forget to name the function explicitly,
using a :: operator?

Right now I've worked around this by adding an extra inheritance level -- an
abstract base class that defines pure virtual functions that I can
explicitly override, but that really shouldn't be necessary, because there's
no technical reason the compiler can't introduce a new set of v-table slots
and fill them all with the same method pointer.  Am I just missing the right
syntax?
Ben Voigt - 30 May 2006 17:06 GMT
>I have a function that is called for several distinct reasons.  It is
>conceivable that a subclass would want to handle those cases differently.
[quoted text clipped - 5 lines]
>
> class XYZ
(I meant ref class)

> {
> protected:
[quoted text clipped - 21 lines]
> v-table slots and fill them all with the same method pointer.  Am I just
> missing the right syntax?
Marcus Heege - 30 May 2006 17:42 GMT
Hi Ben,

>I have a function that is called for several distinct reasons.  It is
>conceivable that a subclass would want to handle those cases differently.
[quoted text clipped - 30 lines]
> v-table slots and fill them all with the same method pointer.  Am I just
> missing the right syntax?
To use named overriding, there must be a vertual function in the base class.
Therefore, you can do this only with the workaround you have descibed.
However, I don't see why you don't implement stubs for all functions.

virtual bool SupportsX() { return false; }
virtual bool SupportsY() { return false; }
virtual bool SupportsZ() { return false; }

Marcus

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.