Is COM interface support method override?

same as subject.
for example

interface ITest : IDispatch
AddParameter(float fA);
AddParameter(bool bA);
The wizard donot support this, Is that can implement some way?

[189 byte] By [XieGuangzhuang] at [2007-12-16]
# 1
Hi,

COM does not support method overloading.
In your case you could make the first parameter a VARIANT so you can investigate the type of the param at runtime. In your C++ implementation you might then use method overloading, e.g.:

interface ITest : IDispatch
{
HRESULT AddParameter([in] VARIANT Param);
};

class YourTestImpl : ITest
{
void addParam(bool);
void addParam(float);

HRESULT AddParameter(VARIANT Param)
{
switch(Param.vt)
{
case VT_BOOL:
addParam(Param.boolVal != VARIANT_FALSE);
break;

case VT_R4: // float
addParam(Param.fltVal);
break;

default:
return E_INVALIDARG;
}

return S_OK;
}
};

HTH,
SvenC

SvenC at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2

Can you pls explain the technical reason behind COM prohibiting Interface method overload? Thank you very much.

seekhelp at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3

I am just guessing here: COM should be useable from different languages and not all of them support overloding. Most important VB <= version 6, which I would name the most prominent language with COM support.

--
SvenC

SvenC at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...