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? 2 1422
"Ben Voigt" <rb*@nospam.nos pam> wrote in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl... 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
(I meant ref class)
{ 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?
Hi Ben,
"Ben Voigt" <rb*@nospam.nos pam> wrote in message
news:uM******** ******@TK2MSFTN GP05.phx.gbl... 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?
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Darius |
last post by:
I'm writing here in hopes that someone can explain the difference
between the new and virtual/override keywords in C#.
Specifically, what is the difference between this:
public class Window
{
public void Draw()
{
Console.WriteLine("The WINDOW Draw method is
running!");
|
by: Dave Y |
last post by:
I am a newbie to C# and am having trouble trying to override a ListView
property method. I have created a new class derived from the Forms.Listview
and I cannot figure out the syntax to override ListView.Items.Add(), . I see
that it is a virtual method so it should be easy to do. If anyone can help I
would appreciate it greatly. I can do what I need to do in a different way
this would just make everything significantly cleaner and eaasier...
|
by: Mark Broadbent |
last post by:
Oh yes its that chestnut again!
Ive gone over the following
(http://www.yoda.arachsys.com/csharp/faq/ -thanks Jon!) again regarding this
subject and performed a few of my own tests.
I have two classes yClass which inherits xClass.
xClass has a virtual method which simply writes a line of text stating its
origin, yClass implements the same method which writes a line of text
stating its origin also (i.e. "From yClass").
I ran the...
|
by: Stoyan |
last post by:
Hi All,
I don't understand very well this part of MSDN:
"Derived classes that override GetHashCode must also override Equals to
guarantee that two objects considered equal have the same hash code;
otherwise, Hashtable might not work correctly."
Does any one know, why we must also override Equals,
Please give my an example:)
Thanks,
Stoyan
|
by: Tony Maresca |
last post by:
Don't know if there are any Delphi/Object Pascal converts
here, but being one, I sorely miss the feature that permits
class (e.g., static) methods to be virtual and be overridden
in derived classes.
Related to that, given:
public class Foo
{
static void SomeMethod()
| |
by: Marcel Hug |
last post by:
Hi NG !
I'm new in C# and I'm reading a book about the fundamentals and concepts.
In the chapter Methods it's written to use virtual, if i would like to
override the method in a subclass. This I've to do by using override.
It's also written, that's possible to "hide" the base class method by
using the new key word.
Because I've already written some C# code and I didn't know anything
|
by: Dave Booker |
last post by:
It looks like the language is trying to prevent me from doing this sort of
thing. Nevertheless, the following compiles, and I'd like to know why it
doesn't work the way it should:
public class ComponentA
{
static string s_name = "I am the root class.";
public string Name { get {return s_name;} }
}
|
by: Aflj |
last post by:
This code won't compile (two compilers tried, gcc and VC++, both of recent versions, but I don't remember them exactly):
class C1
{
public:
void M1(int i) {}
};
class C2: public C1
|
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= |
last post by:
Hi,
I have a moderately complex class (about 10 different string and int
type fields along with two different List<stringfields). I want to override
Equals(), so I need to override GetHashCode(). The standard override for
GetHashCode() for something would be to join GetHashCode for each field with
^ (XOR). Right? But, in this case, one of the fields is a "Unique" Identifier
and SHOULD uniquely identify the instance of the class. If that is...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |