ATL bug with CComPtr and VS2003 ?
-
I am using ATL with Visual Studio.NET 2003. I seem to be having a problem with template member specialization involving the CComPtr<> class declared in atlcomcli.h. In the declaration for CComPtr<> the last entry for a member function is: template <> T* operator=(const CComPtr& lp) throw() { return static_cast(AtlComPtrAssign((IUnknown**)&p, lp)); } The code I am working with declares a template member specialization similar to this: CFoo* CComPtr::operator=(const CComPtr & lp) { ... } In VS.NET 2002 this works just fine. However, in VS.NET 2003 I get compiler error C2511 (overloaded member function not found ...). I can remove the line 'template <>' from the CComPtr<> class declaration in atlcomcli.h (shown above) and the code will then compile just fine. Is this a bug in ATL or is there something I am not seeing? Since I don't want to modify the original ATL files, I have made special modified copies of atlcomcli.h and, by necessity, atlbase.h and I have included them in the project in order to do a workaround. Is there a better way? Thank you, Ray Gregory
-
I am using ATL with Visual Studio.NET 2003. I seem to be having a problem with template member specialization involving the CComPtr<> class declared in atlcomcli.h. In the declaration for CComPtr<> the last entry for a member function is: template <> T* operator=(const CComPtr& lp) throw() { return static_cast(AtlComPtrAssign((IUnknown**)&p, lp)); } The code I am working with declares a template member specialization similar to this: CFoo* CComPtr::operator=(const CComPtr & lp) { ... } In VS.NET 2002 this works just fine. However, in VS.NET 2003 I get compiler error C2511 (overloaded member function not found ...). I can remove the line 'template <>' from the CComPtr<> class declaration in atlcomcli.h (shown above) and the code will then compile just fine. Is this a bug in ATL or is there something I am not seeing? Since I don't want to modify the original ATL files, I have made special modified copies of atlcomcli.h and, by necessity, atlbase.h and I have included them in the project in order to do a workaround. Is there a better way? Thank you, Ray Gregory
In standard C++, you can't just specialize a single member function of a template class. You have to specialize the whole class template. Earlier versions of Visual C++ erroneously allowed this. Why do you need to specialize
CComPtr
? You should normally be using this class with COM interfaces; if you're trying to use it with something else, I suggest writing a smart pointer template of your own. UsingCComPtr
with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris Maunder -
In standard C++, you can't just specialize a single member function of a template class. You have to specialize the whole class template. Earlier versions of Visual C++ erroneously allowed this. Why do you need to specialize
CComPtr
? You should normally be using this class with COM interfaces; if you're trying to use it with something else, I suggest writing a smart pointer template of your own. UsingCComPtr
with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris MaunderI have found that I can specialize the single member function just by removing the line '
template <>
' that immediately precedes the declaration of theoperator=
function in the delcaration forCComPtr
in atalcomcli.h. I have to specialize theoperator=
member function ofCComPtr
to avoid a compiler error about ambiguous conversions. The specialized function does the same thing as the default function with the exception of some typecasting. -
In standard C++, you can't just specialize a single member function of a template class. You have to specialize the whole class template. Earlier versions of Visual C++ erroneously allowed this. Why do you need to specialize
CComPtr
? You should normally be using this class with COM interfaces; if you're trying to use it with something else, I suggest writing a smart pointer template of your own. UsingCComPtr
with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris MaunderThe class
CFoo
is a COM interface. It inherits multiply from, among other things,IDropSource
andIDropTarget
. In fact this is the reason I need to specialize the asignment operator forCComPtr<CFoo>
. If I don't, then the compiler signals ambiguous conversions betweenCFoo*
andIUnknown*
because bothIDropSource
andIDropTarget
derive fromIUnknown
. Unfortunately, the specialized copy asignment operator breaks in VS 2003 but not in VS 2002. -
The class
CFoo
is a COM interface. It inherits multiply from, among other things,IDropSource
andIDropTarget
. In fact this is the reason I need to specialize the asignment operator forCComPtr<CFoo>
. If I don't, then the compiler signals ambiguous conversions betweenCFoo*
andIUnknown*
because bothIDropSource
andIDropTarget
derive fromIUnknown
. Unfortunately, the specialized copy asignment operator breaks in VS 2003 but not in VS 2002.