Solved

COM and Overloaded Operators

Posted on 2000-05-12
4
227 Views
Last Modified: 2013-12-14
We are looking to create a C++ COM component.  We want to be able to overload the mathematical operators (+, -, *, /).  Is it possible to expose these overloaded operators through our IDL and interface?  Also, the operator will only be performed on objects of the Class it is overloaded for, so commutativity is not needed, so would we need to make the operator a friend function?
0
Comment
Question by:chayes050498
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:AssafLavie
ID: 2807299
I believe it's impossible to overload operators in IDL.
0
 
LVL 1

Expert Comment

by:arbitrary
ID: 2808543
Since COM is a framework and IDL is build
to provide interface for multiple programming languages, you cannot overload operators on the IDL file.

What you can do if you desire is to provide a external header that overload the operators for the exported interface or the Smart pointer created from the coclass , or create a class that inherit from the SmartPtr or the Interface and overload the operators on this class.

for example :

for the interface IHTMLElement i create a wrapper that initialize the interface on object construction and override the operators for that wrapper class

class Example : public IHTMLElement
{
public :
      Example(){

             //CoCreateInstance()

AddRef();
            }
      ~Example(){
                  Release();
            }
      Example& operator +(const Example&);
      Example & operator -(const Example &);

};



0
 
LVL 1

Accepted Solution

by:
arbitrary earned 100 total points
ID: 2808592
And you can also inherit from the SmartPtr wrapped Interface.
0
 

Author Comment

by:chayes050498
ID: 2810774
Thanks
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question