Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

COM and Overloaded Operators

Posted on 2000-05-12
4
Medium Priority
?
230 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 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

885 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