what is advantage to use CAdapt in Map or vector 
Author Message
 what is advantage to use CAdapt in Map or vector

Hi,
 I would like know about CAdapt<> .i am using in  my ATL code .up to my
understanding whenever i will pass class pointer or interface poiner
parameter to Map or Vector.it is good to use CAdapt .

example :

 std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

what does make sense about passing  the interface pointer to CAdapt .

can any one explain clearly..

with best wishes
Manoj



Fri, 04 Jun 2004 14:04:21 GMT  
 what is advantage to use CAdapt in Map or vector
Manoj,

The STL storage classes assume that the addressof (&) operator isn't
overloaded - which is exactly what CComPtr does. Using CAdapt hides this
from the STL storage classes so that there are no problems.


Quote:
> Hi,
>  I would like know about CAdapt<> .i am using in  my ATL code .up to my
> understanding whenever i will pass class pointer or interface poiner
> parameter to Map or Vector.it is good to use CAdapt .

> example :

>  std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

> what does make sense about passing  the interface pointer to CAdapt .

> can any one explain clearly..

> with best wishes
> Manoj



Fri, 04 Jun 2004 16:03:43 GMT  
 what is advantage to use CAdapt in Map or vector
Hi yury,
 it mean it hide the address-of operator .i wanted how it works internally.
if i will not use CAdapt<> then what are the problem occur...

with Best wishes
Manoj


Quote:
> Manoj,

> The STL storage classes assume that the addressof (&) operator isn't
> overloaded - which is exactly what CComPtr does. Using CAdapt hides this
> from the STL storage classes so that there are no problems.



> > Hi,
> >  I would like know about CAdapt<> .i am using in  my ATL code .up to my
> > understanding whenever i will pass class pointer or interface poiner
> > parameter to Map or Vector.it is good to use CAdapt .

> > example :

> >  std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

> > what does make sense about passing  the interface pointer to CAdapt .

> > can any one explain clearly..

> > with best wishes
> > Manoj



Fri, 04 Jun 2004 18:34:58 GMT  
 what is advantage to use CAdapt in Map or vector
Manoj,

If you don't use CAdapt with parameters of STL templates that redefine the
address-of operator, you simply won't be able to compile. For example, say
you have the following imaginary STL class:

template <class T>
class imaginary_stl_storage_class
{
public:
    void any_function( T& item )
   {
        T* pointer = &item;
   }

Quote:
};

Now you do this:

CComPtr<IUnknown> p;
imaginary_stl_storage_class< CComPtr<IUnknown> > cls;
cls.any_function( p );

So when the compiler sees this:

T* pointer = &item;

it translates it into

CComPtr<IUnknown>* pointer = &item;

however, because &item is overriden, it does not return a
CComPtr<IUnknown>*, instead it returns an IUnknown*.

so the compiler gives an error because it sees that you're trying to assign
an IUnknown pointer to a CComPtr<IUnknown> pointer.

Hope that cleared things up,
Yury


Quote:
> Hi yury,
>  it mean it hide the address-of operator .i wanted how it works
internally.
> if i will not use CAdapt<> then what are the problem occur...

> with Best wishes
> Manoj



> > Manoj,

> > The STL storage classes assume that the addressof (&) operator isn't
> > overloaded - which is exactly what CComPtr does. Using CAdapt hides this
> > from the STL storage classes so that there are no problems.



> > > Hi,
> > >  I would like know about CAdapt<> .i am using in  my ATL code .up to
my
> > > understanding whenever i will pass class pointer or interface poiner
> > > parameter to Map or Vector.it is good to use CAdapt .

> > > example :

> > >  std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

> > > what does make sense about passing  the interface pointer to CAdapt .

> > > can any one explain clearly..

> > > with best wishes
> > > Manoj



Fri, 04 Jun 2004 19:41:00 GMT  
 what is advantage to use CAdapt in Map or vector
Hi Yury,

See reply inline

 T* pointer = &item;
 it translates it into
 CComPtr<IUnknown>* pointer = &item;

 however, because &item is overriden, it does not return a
 CComPtr<IUnknown>*, instead it returns an IUnknown*.

Manoj : ==>  if  i use  as CAdapt<> then it will not override the & operator
and it will return as  CComPtr<IUnknown>*,  instead it returns an IUnknown*.

 so the compiler gives an error because it sees that you're trying to assign
 an IUnknown pointer to a CComPtr<IUnknown> pointer.

Manoj : ==> Here i am not clear ..i can assign  raw pointer with smart
pointer ..there is nothing worng....

With best wishes
Manoj


Quote:
> Manoj,

> If you don't use CAdapt with parameters of STL templates that redefine the
> address-of operator, you simply won't be able to compile. For example, say
> you have the following imaginary STL class:

> template <class T>
> class imaginary_stl_storage_class
> {
> public:
>     void any_function( T& item )
>    {
>         T* pointer = &item;
>    }
> };

> Now you do this:

> CComPtr<IUnknown> p;
> imaginary_stl_storage_class< CComPtr<IUnknown> > cls;
> cls.any_function( p );

> So when the compiler sees this:

> T* pointer = &item;

> it translates it into

> CComPtr<IUnknown>* pointer = &item;

> however, because &item is overriden, it does not return a
> CComPtr<IUnknown>*, instead it returns an IUnknown*.

> so the compiler gives an error because it sees that you're trying to
assign
> an IUnknown pointer to a CComPtr<IUnknown> pointer.

> Hope that cleared things up,
> Yury



> > Hi yury,
> >  it mean it hide the address-of operator .i wanted how it works
> internally.
> > if i will not use CAdapt<> then what are the problem occur...

> > with Best wishes
> > Manoj



> > > Manoj,

> > > The STL storage classes assume that the addressof (&) operator isn't
> > > overloaded - which is exactly what CComPtr does. Using CAdapt hides
this
> > > from the STL storage classes so that there are no problems.



> > > > Hi,
> > > >  I would like know about CAdapt<> .i am using in  my ATL code .up to
> my
> > > > understanding whenever i will pass class pointer or interface poiner
> > > > parameter to Map or Vector.it is good to use CAdapt .

> > > > example :

> > > >  std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

> > > > what does make sense about passing  the interface pointer to CAdapt
.

> > > > can any one explain clearly..

> > > > with best wishes
> > > > Manoj



Fri, 04 Jun 2004 22:41:58 GMT  
 what is advantage to use CAdapt in Map or vector
It is not a smart pointer class - it is a pointer to a smart pointer
class. Remember, syntactically a smart pointer is not a pointer :)...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi Yury,

> See reply inline

>  T* pointer = &item;
>  it translates it into
>  CComPtr<IUnknown>* pointer = &item;

>  however, because &item is overriden, it does not return a
>  CComPtr<IUnknown>*, instead it returns an IUnknown*.

> Manoj : ==>  if  i use  as CAdapt<> then it will not override the &
operator
> and it will return as  CComPtr<IUnknown>*,  instead it returns an
IUnknown*.

>  so the compiler gives an error because it sees that you're trying to
assign
>  an IUnknown pointer to a CComPtr<IUnknown> pointer.

> Manoj : ==> Here i am not clear ..i can assign  raw pointer with smart
> pointer ..there is nothing worng....

> With best wishes
> Manoj



> > Manoj,

> > If you don't use CAdapt with parameters of STL templates that redefine
the
> > address-of operator, you simply won't be able to compile. For example,
say
> > you have the following imaginary STL class:

> > template <class T>
> > class imaginary_stl_storage_class
> > {
> > public:
> >     void any_function( T& item )
> >    {
> >         T* pointer = &item;
> >    }
> > };

> > Now you do this:

> > CComPtr<IUnknown> p;
> > imaginary_stl_storage_class< CComPtr<IUnknown> > cls;
> > cls.any_function( p );

> > So when the compiler sees this:

> > T* pointer = &item;

> > it translates it into

> > CComPtr<IUnknown>* pointer = &item;

> > however, because &item is overriden, it does not return a
> > CComPtr<IUnknown>*, instead it returns an IUnknown*.

> > so the compiler gives an error because it sees that you're trying to
> assign
> > an IUnknown pointer to a CComPtr<IUnknown> pointer.

> > Hope that cleared things up,
> > Yury



> > > Hi yury,
> > >  it mean it hide the address-of operator .i wanted how it works
> > internally.
> > > if i will not use CAdapt<> then what are the problem occur...

> > > with Best wishes
> > > Manoj



> > > > Manoj,

> > > > The STL storage classes assume that the addressof (&) operator isn't
> > > > overloaded - which is exactly what CComPtr does. Using CAdapt hides
> this
> > > > from the STL storage classes so that there are no problems.



> > > > > Hi,
> > > > >  I would like know about CAdapt<> .i am using in  my ATL code .up
to
> > my
> > > > > understanding whenever i will pass class pointer or interface
poiner
> > > > > parameter to Map or Vector.it is good to use CAdapt .

> > > > > example :

> > > > >  std::map<CAdapt< CComptr<IXXX> >,int > iMap ;

> > > > > what does make sense about passing  the interface pointer to
CAdapt
> .

> > > > > can any one explain clearly..

> > > > > with best wishes
> > > > > Manoj



Sat, 05 Jun 2004 03:40:03 GMT  
 what is advantage to use CAdapt in Map or vector

Quote:
> Hi Yury,

> See reply inline

>  T* pointer = &item;
>  it translates it into
>  CComPtr<IUnknown>* pointer = &item;

>  however, because &item is overriden, it does not return a
>  CComPtr<IUnknown>*, instead it returns an IUnknown*.

> Manoj : ==>  if  i use  as CAdapt<> then it will not override the &
operator
> and it will return as  CComPtr<IUnknown>*,  instead it returns an

IUnknown*.

If you do not use CAdapt, then our imaginary templatized statement
expands into

CComPtr<IUnknown> item;
CComPtr<IUnknown> >* pointer = &item;

Since CComPtr::operator& is overloaded, &item is of type IUnknown** -
type mismatch.

If you use CAdapt, you have

CAdapt<CComPtr<IUnknown> > item;
CAdapt<CComPtr<IUnknown> >* pointer = &item;

CAdapt does not overload operator&, so &item is of type CAdapt<...>* -
no type mismatch.

Quote:
>  so the compiler gives an error because it sees that you're trying to
assign
>  an IUnknown pointer to a CComPtr<IUnknown> pointer.

> Manoj : ==> Here i am not clear ..i can assign  raw pointer with smart
> pointer ..there is nothing worng....

You can assign like this

IUnknown *item;
CComPtr<IUnknown> sp = item;

But what goes on inside STL templates is more like

IUnknown *item;
CComPtr<IUnknown> *psp = &item;

I.e. IUnknown** being assigned to CComPtr<IUnknown>*. That does not
compile.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sat, 05 Jun 2004 04:05:57 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Map using vector

2. Accessing map elements in vector of maps

3. Bug exposed when using CAdapt

4. Advantage of memory mapped files

5. Advantage of memory mapped files

6. What am I doing wrong with vector interrupts?

7. Am I being paranoid about vector pointers?

8. Problem with using map .erase inside a map loop

9. Any advantages in using unsigned char ?

10. Advantages/Disadvantages of using float vs double

11. whats the advantages in using macros

12. What's the advantage using malloc??

 

 
Powered by phpBB® Forum Software