Re: Collection Copy Policy in ATL8-vs2005
Hi Townee,
"Townee" <zhp80@sina.com> wrote in message
news:eIMBir82GHA.3464@TK2MSFTNGP03.phx.gbl...
Thanks
I know that is is a problem of const correctness.
in VC 2005
template <.....>
class ICollectionOnSTLImpl:public T
{
....
....
STDMETHOD(get_Item)(long Index, ItemType* pvar)
{
......
......
CollType::const_iterator iter = m_coll.begin();
......
.....
I insert const on any position :
typename typedef const ContainerType::value_type SourceType;
or
static HRESULT copy(InterfaceType** pTo, const SourceType* pFrom )
{
return _CopyInterface<InterfaceType>::copy(pTo, &(pFrom->second));
}
To compile every mode is
error C2664: 'ATL::_CopyInterface<T>::copy' : cannot convert parameter 2
from 'IObjA *const *__w64 ' to 'IObjA **'
_CopyInterface's copy method seems to be not const correct. You have to
const_cast the second parameter or change the ATL code to make the second
parameter const correct. To not depend on such a change which you would nee
on any machine you install ATL and use that code, try:
return _CopyInterface<InterfaceType>::copy(pTo,
const_cast<IObjA**>(&(pFrom->second)));
I'm not sure about your typedefs, maybe you want to use
const_cast<SourceType*>(...)
--
SvenC
Where the const is inseted will is RIGHT?
Thanks in advance,
ZHP.Henry