CAdapt Class

This template is used to wrap classes that redefine the address-of operator to return something other than the address of the object.

template < 
   class T 
> 
class CAdapt

Parameters

  • T
    The adapted type.

Members

Public Constructors

Name

Description

CAdapt::CAdapt

The constructor.

Public Operators

Name

Description

CAdapt::operator const T&

Returns a const reference to m_T.

CAdapt::operator T&

Returns a reference to m_T.

CAdapt::operator <

Compares an object of the adapted type with m_T.

CAdapt::operator =

Assigns an object of the adapted type to m_T.

CAdapt::operator ==

Compares an object of the adapted type with m_T.

Public Data Members

Name

Description

CAdapt::m_T

The data being adapted.

Remarks

CAdapt is a simple template used to wrap classes that redefine the address-of operator (operator &) to return something other than the address of the object. Examples of such classes include ATL's CComBSTR, CComPtr, and CComQIPtr classes, and the compiler COM support class, _com_ptr_t. These classes all redefine the address-of operator to return the address of one of their data members (a BSTR in the case of CComBSTR, and an interface pointer in the case of the other classes).

CAdapt's primary role is to hide the address-of operator defined by class T, yet still retain the characteristics of the adapted class. CAdapt fulfils this role by holding a public member, m_T, of type T, and by defining conversion operators, comparison operators, and a copy constructor to allow specializations of CAdapt to be treated as if they are objects of type T.

The adapter class CAdapt is useful because some container-style classes expect to be able to obtain the addresses of their contained objects using the address-of operator. The redefinition of the address-of operator can confound this requirement, typically causing compilation errors and preventing the use of the non-adapted type with classes that expect it to "just work". CAdapt provides a way around those problems.

Typically, you will use CAdapt when you want to store CComBSTR, CComPtr, CComQIPtr, or _com_ptr_t objects in a container-style class. This was most commonly necessary for C++ Standard Library containers prior to support for the C++11 Standard, but C++11 Standard Library containers automatically work with types that have overloaded operator&(). The Standard Library achieves this by internally using std::addressof() to get the true addresses of objects.

Requirements

Header: atlcomcli.h

See Also

Other Resources

ATL Class Overview