I really don't want to, but I have to emulate COM logic in my program and I'm using standard COM_ADDREF macros, but I keep getting the following error: invalid conversion from 'void ()(MyObject, bool)' to 'const void*'... What should I do?
#define COM_ADDREF(pObj, pMaster) ((pObj)->AddRef((pMaster), __FILE__, __LINE__, pObj))
class BaseComObject
{
public:
inline DWORD AddRef (const void* pMaster, const char* pFileName, int line, const void* pObj) const
{
iRefCount++;
return iRefCount;
};
inline DWORD GetRefCount() const
{
return iRefCount;
};
private:
long iRefCount;
};
class MyObject: public BaseComObject { };
void test (MyObject* pObject, bool bValue)
{
if (pObject)
{
COM_ADDREF (pObject, bValue);// error: invalid conversion from 'void (*)(MyObject*, bool)' to 'const void*'
}
}
error: invalid conversion from 'void ()(MyObject, bool)' to 'const void*'
error: initializing argument 1 of 'DWORD BaseComObject::AddRef(const void*, const char*, int, const void*) const'
COM_ADDREF ( (void*)pObject, bValue);- Kiril Kirovbool bValuetoconst void* pMaster), but the error implies you're using a function, not abool, as the second argument ofCOM_ADDREF. - Mike SeymourCOM_ADDREF(pObject, (void*)bValue)if you simply want to make it compile; however, casting aboolto a pointer is almost certainly going to go horribly wrong (and wouldn't work anyway if, as the error message implies, it's actually a function rather than abool). - Mike Seymourmysql_optionfunction works (almost) this way (from the MySQL lib). - Kiril Kirov