473,793 Members | 2,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can operators be inherited?

I don't recall whether operators, which are members of the class, are
intherited in subclasses?

thanks

Aug 1 '07 #1
5 2656
puzzlecracker wrote:
I don't recall whether operators, which are members of the class, are
intherited in subclasses?
If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.

If you meant to ask if we thought you didn't recall, we don't know.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '07 #2
Victor Bazarov wrote:
puzzlecracker wrote:
>I don't recall whether operators, which are members of the class, are
intherited in subclasses?

If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.
Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '07 #3
On Aug 1, 11:25 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Victor Bazarov wrote:
puzzlecracker wrote:
I don't recall whether operators, which are members of the class, are
intherited in subclasses?
If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.

Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.

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

What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?

Thanks agai,
Aug 1 '07 #4
puzzlecracker wrote:
[..]
What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?
Hiding and overriding are two different concepts, but hiding can be
overcome by "using" declarations (see FAQ).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 1 '07 #5
On Aug 1, 6:07 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
On Aug 1, 11:25 am, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Victor Bazarov wrote:
puzzlecracker wrote:
>I don't recall whether operators, which are members of the class, are
>intherited in subclasses?
If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.
Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.
What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?
As far as the definition goes, a user defined operator is just a
function with a funny name, and it obeys all of the rules of a
function.

A more general comment, however: C++ operators are value
oriented, and values and polymorphism don't really mix very
well. So the presence of a virtual operator is *usually* a
symptom of a design error (although there are one or two
specific idioms, like letter/envelope where it makes sense).
Just because you can do something doesn't mean that you should.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
2531
by: greg | last post by:
Discussion is invited on the following proto-PEP. ------------------------------------------------------------- PEP ??? - Overloadable Boolean Operators ======================================== SUMMARY This PEP proposes an extension to permit objects to define their own
6
3666
by: Christian Brechbühler | last post by:
The template std::valarray behaves pretty much like a mathematical vector. Arithmetic operators apply elementwise. Now I'd like to extend this to a user-defined type, e.g., complex. Multiplying a double by a complex number gives a complex number. Now I would like to multiply a valarray of doubles by a complex number and get a valarray of complex numbers. Of course, a C++ compiler won't jump to that conclusion; I need to define...
5
6888
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: // TestA.h --------------------------------------- #include <iostream> enum Aval { FIRST_VALUE,
6
2023
by: Raf256 | last post by:
Hi, I would extend class only a bit. In example: I want to write my own class, that works all like std::string, only it also have member int mDatabase; and it have method SaveToDatabase(); I could do like: class cStorableStr : std::string { private: int mDatabase;
25
2586
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing constants in Python language. There are some workarounds available, for example the const-module. To me, this looks quite cumbersome and very unintuitive. For the interpreter, in the efficiency-wise, I just cannot tell.
1
1308
by: Dave Rudolf | last post by:
Hey all, The best way to explain my problem is with an example, so here goes: I have a class that I use to represent a numeric vector (i.e., a point in some multi-dimensional space). The class has operators for assignment, addition, etc. So, for example, the essentials of the class are class NumericVector
5
1283
by: Shak | last post by:
Hi all. I was led to believe that static methods were not inherited by their subclasses (and since that makes sense, rightly so). However, a subclass I've written is using it's (abstract) superclass's operators. How can that be when operators are always static? Is it a special case? It's handy, sure, but doesn't it "break" the language somehow? Or isn't this actually inheritance at play here?
1
1533
by: Kambehba | last post by:
Would you please tell me that if the Base class constructors and assignment operators are inherited by the derived classes or not. and any more information that apply. Thank you. kambiz
3
1366
by: Noodle | last post by:
Hi Guys, not sure if anyone can help me on this one but...... I have a class that I overload the equality operator (=). I also have a class that inherits from this first class which has extra attributes that i need to check to see if they are equal for the previous overload to work correctly. No my question is how do I do this? The obvious answer is to overload the overloaded operator and then copy the comparison routine from the...
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10430
Oralloy
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...
0
10211
jinu1996
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...
1
10159
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,...
0
9033
agi2029
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...
1
7538
isladogs
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...
0
6776
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();...
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.