Solved

COM and Overloaded Operators

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 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

20 Experts available now in Live!

Get 1:1 Help Now