Search code examples
c++winapic-stringsatl

Does CPath perform reference counting?


I was wondering whether ATL's CPath behaves like the underlying CString, in that an assignment will result in a ref count rather than a deep copy. I don't see anything in the docs about it, and I'm not sure how to test it. Here's some source that may be relevant, though I'm not sure:

template< typename StringType >
class CPathT
{
public:
    typedef typename StringType::XCHAR XCHAR;
    typedef typename StringType::PCXSTR PCXSTR;
    typedef typename StringType::PXSTR PXSTR;

public:
    CPathT() throw()
    {
    }
    CPathT(_In_ const CPathT< StringType >& path) :
        m_strPath( path.m_strPath )
    {
    }
    CPathT(_In_z_ PCXSTR pszPath) :
        m_strPath( pszPath )
    {
    }

    operator const StringType& () const throw()
    {
        return m_strPath;
    }
    operator StringType& () throw()
    {
        return m_strPath;
    }
    operator PCXSTR() const throw()
    {
        return m_strPath;
    }
    
    ...

public:
    StringType m_strPath;
};

typedef CPathT< CString > CPath;

Thank you very much for any info.


Solution

  • As you showed in the code above, the CPath is just a wrapper for CString, so it encapsulates all its properties and behavior. Logically, it uses CString reference counting.