Re: CComPtr subtlety
Jason S <jmsachs@gmail.com> wrote:
The second constructor is a copy constructor. If you don't provide
one, compiler automatically generates a copy constructor that simply
performs member-wise copy.
is member-wise copy equivalent to:
(a) calling the copy constructor for each member
(b) running memcpy() on the class/structure
The former. Of course, for fundamental types a "copy constructor" is
equivalent to memcpy.
I thought it was (a), in which case I don't think you'd need both
forms, since CComPtr contains a cast operator to the raw pointer
CComPtr<IMyInterface> p;
CComPtr<IMyInterface> q (x); // first one
CComPtr<IMyInterface> r (p); // second one
e.g. the second one could be accomplished by the compiler by calling
the (IMyInterface *) operator on p
But the compiler doesn't do that, because CComPtr(const CComPtr&)
overload is a better match. And again, this overload is always present,
even if you don't explicitly write it.
Having said that, I don't see what this has to do with your (a) and (b)
choices above. The only data member of CComPtr<T> is a raw pointer T* p;
member-wise copy constructor would just copy the pointer.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925