HELP: error C2664 in atlcom.h coming back

Moving from vs2003 to vs2005, I have the following compilation error:

atlcom.h (5005) : errror C2664: 'ATL::_CopyInterface<T>::copy' : cannot convert parameter 2 from 'IMyObject  *const *' to 'IMyObject **'

with

[

T = IMyObject

]

Conversion loses qualifiers

atlcom.h (4992) : while compiling class templates member function 'HRESULT ATL::IEnumOnSTLImpl<Base, piid, T, Copy, CollType>::Next(ULONG, T *, ULONG *)'

with

[

Base = IEnumMyObject

piid = & IID_IEnumMyObject,

T = IMyObject *,

Copy = ATL::_CopyInterface<IMyObject>,

CollType = std::vector<IMyObject *>

]

Having compared the two atlcom.h files between vs2003 and vs2005, the only difference I found concerns the member 'm_iter' of IEnumOnSTLImpl defined as:

typename CollType::iterator m_iter in Vs2003

typename CollType::const_iterator m_iter in Vs2005

 

As suggested in a previous post, this kind of error can be solved by changing the copy method to accept const objects.

But in my case, ATL::_CopyInterface<T>::copy is from ATL library code.

What can I do

Fabien.

 



Answer this question

HELP: error C2664 in atlcom.h coming back

  • Rynus_Rein

    This is a static function and should be called in this way:

    CComObject<OENUM>* pe = NULL;
    HRESULT hr = CComObject<OENUM>::CreateInstance(&pe);



  • alanr

    Here it is:

    template<class I, class IENUM, class OENUM>
    class ATL_NO_VTABLE CMyTrack :

    public CComObjectRootEx<CComMultiThreadModel>,
    public CComCoClass<CMyTrack, &CLSID_MyTrack>,
    public IMyTrack
    {
    public:
    BEGIN_COM_MAP(CMyTrack)
    COM_INTERFACE_ENTRY(IMyTrack)
    END_COM_MAP()

    CMyTrack();
    ...
    private:
    ...
    vector<IMyObj*> mMyObjs;
    ...
    };

    HRESULT __stdcall CMyTrack::FormsEnum(long *O_plCount, IEnumMyObj ** O_ppEnum)
    {
    return EnumMyObj<IMyObj, IEnumMyObj, CEnumMyObj>(O_plCount, O_ppEnum, mMyObjs, GetUnknown())
    }


    template<class I, class IENUM, class OENUM>
    HRESULT CMyTrack::EnumMyObj(long *O_plCount, IENUM** O_ppEnum, vector<I*>& O_vecInterface, IUnknown* pUnknown)
    {
    CComObject<OENUM>* pe = NULL;

    HRESULT hr = pe->CreateInstance(&pe); //<- Commenting this line removes compilation error.
    //Also changing IEnumOnSTLImpl::m_iter in atlcom.h from const_iterator into iterator solves the problem

    }


  • Blakeyrat

    Show us the code were this error occurs.

  • dbw

    the compilation error still occurs....

    And if I remove totally the CreateInstance call, I have the same problem onthe next call:

    pe->AddRef();

    HELP Please...

     


  • Azam Abdul Rahim

    Sounds like you need to make one of the parameters in your implemented functions, or the function itself const. It's actually a good practice to make ALL of your parameters and functions const if they in fact do not change the object or the reference since it helps the compiler optimize. So feel free to sprinkle them everywhere that makes sense.

    -Ben



  • HELP: error C2664 in atlcom.h coming back