chayes050498
asked on
COM and Overloaded Operators
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?
I believe it's impossible to overload operators in IDL.
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 &);
};
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 &);
};
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks