Solved

COM and Overloaded Operators

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ Language error 28 218
Eclipse. How to move up/down source folders 4 88
C++ question 3 66
Best book to learn C++ 4 79
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

832 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