Click to See Complete Forum and Search --> : Type casting issue


Fr0zenBrain
March 7th, 2003, 01:08 AM
This piece of code used to compile without any errors or warnings in vc6. NOw it is giving errors.


vector < CAdapt< CComPtr<IMyField> > >::iterator theIterator;

for ( theIterator = m_coll.begin(); theIterator != m_coll.end(); theIterator++ )
{
CComPtr<IMyField> Fld;
Fld = *theIterator


Error :


error C2679: binary '=' : no operator found which takes a right-hand operand of type 'ATL::CAdapt<<T>T>' (or there is no acceptable conversion)
with

[
T=ATL::CComPtr <<IMyField>IMyField>
]

Paul McKenzie
March 7th, 2003, 01:42 AM
I know nothing about COM, but what you wrote shouldn't have even compiled under VC 6. Isn't CComPtr a template? So where is the template argument for CComPtr when you defined CAdapt and where you defined Fld? Here is how it's defined that I found on MSDN:

template <class T>
class CComPtr
{
//...
};

So I'm curious why VC 6 didn't flag you for an error for the lines where you are missing the CComPtr template argument. I would have expected CComPtr< int > or something like that, not just CComPtr (Unless you inadvertantly left out the template argument).

Regards,

Paul McKenzie

Fr0zenBrain
March 7th, 2003, 03:34 AM
Well I gues there is some problem with the content parsing of codeguru posts. Anything written enclosed in <> is not being displayed. It was ImyFields written in <> of CComPtr template. I hope it works this time.

vector < CAdapt< CComPtr > >::iterator theIterator;

for ( theIterator = m_coll.begin(); theIterator != m_coll.end(); theIterator++ )
{
CComPtr<IMyField> Fld;
Fld = *theIterator