Solved

COM and Overloaded Operators

Posted on 2000-05-12
4
213 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
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…

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now