473,732 Members | 2,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

operator overloading and virtual funtions

hi all experts,

i was just thinking about making overloaded operators virtual. i was
wordering what could be the
implications of such scenarios.
i will be thankful if somebody can provide point out some general
issues in making overloaded virtual or point me to some resource
having explaination about the same.

thanks
ravinder.

Jan 30 '06 #1
1 6650
On 30 Jan 2006 04:56:52 -0800, ra************@ gmail.com wrote:
hi all experts,

i was just thinking about making overloaded operators virtual. i was
wordering what could be the
implications of such scenarios.
i will be thankful if somebody can provide point out some general
issues in making overloaded virtual or point me to some resource
having explaination about the same.


Have you read the FAQ yet?
http://www.parashift.com/c++-faq-lit...erloading.html

Don't forget that there is a difference between overloading and
overriding. Overloaded functions (or operators) take different
arguments, but they are in the same class or namespace. However,
virtual functions need to be overridden, which means they have to take
the same arguments in the derived class as in the base class. If you
truly overload a virtual function or operator by providing different
arguments, you will likely end up hiding the base class virtual
function or operator.

--
Bob Hairgrove
No**********@Ho me.com
Jan 30 '06 #2

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

Similar topics

6
7206
by: Victor | last post by:
Anyone knows how to write a virtual function for operator<< ? I have a base class and some public derived class from it. For the derived class, I hope they can use << to output their different data. What's more, I want the base class pointers can access the derived ones and then their corresponding operator <<. For example: class base { // virtual and friend can't be put together, so the following // code won't work.
17
3739
by: N4M | last post by:
Dear, Suppose I have a Protocol class, in which I need also an assignment operator =(). class B { ..... virtual B& operator=(const B& rb) =0; }; Now in some derived class D: public B, how would I proceed with operator=? Do I need to supply 2 operators:
2
11521
by: Shark | last post by:
Hi, if we need to change the behavior of operator new, it is called overriding or overloading? My other question is, if we change the behavior of operator new, do we use malloc to do that or we use operator new?
2
7395
by: Tom Smith | last post by:
I'm having difficulty with overloading ==, and it's making my brain melt - can you help...? What I want to have is: 1) A base class A with virtual operator== defined (no problem) 2) A class B derived from A with operator== overridden (again, no problem) 3) Pointers A* b1, b2 which may actually point to instances of B, where I can call (*b1)==(*b2) and have it use the overridden form of == found in B. Having written this all out I'm...
2
3086
by: www.brook | last post by:
I want to enfore the implementation of the operator overloading eg class Interface_ { public: virtual void operator = (const Interface &other)=0; virtual void operator +=(const Interface &other)=0; } but in the sub class
2
1720
by: Gonçalo Rodrigues | last post by:
Hi all, I could have sworn the c++ faq had the answer for this question but I can't seem to find it, so here goes: Suppose you have a single-rooted class hierarchy. Call the root class Object. How can we provide operator overloading for the whole hierarchy? e.g. provide == for the whole hierarchy? Even more specifically: suppose we define
5
2273
by: noone | last post by:
hi. I don't use exceptions much in the embedded world, but for my plugin interface to a hardware MPEG encoder I'd like to, since there are so many places that the crummy kernel driver can do bad things to my userland program. I hope this news client doesn't reformat my example below and make it impossible to read. :^) consider the following exception heirarchy
14
2337
by: Hunk | last post by:
Hi I ws wondering if there is a way to implement operator+ in case of virtual classes. Here's the problem. I have to have a base string class from which two classes (normal char string and a hash string class ) are derived. The two derived classes are template classes specifying the sizes. The base class is a non-template class so that it can be used generically in the interface classes. the design would look like
6
4733
by: Rob McDonald | last post by:
I would like to force all the classes in my hierarchy to implement the << operator for testing purposes. My base class is a pure virtual class. I started out by working with operator overloading in the derived class. I have been trying to use what I learned there to create an appropriate virtual class to force overloading. class Base{
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
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
9235
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
8186
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...
0
6031
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();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.