Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. ATL bug with CComPtr and VS2003 ?

ATL bug with CComPtr and VS2003 ?

Scheduled Pinned Locked Moved ATL / WTL / STL
helpcsharpvisual-studioc++question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ray Gregory
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • R 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

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      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. Using CComPtr with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris Maunder

      R 2 Replies Last reply
      0
      • M Mike Dimmick

        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. Using CComPtr with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris Maunder

        R Offline
        R Offline
        Ray Gregory
        wrote on last edited by
        #3

        I have found that I can specialize the single member function just by removing the line 'template <>' that immediately precedes the declaration of the operator= function in the delcaration for CComPtr in atalcomcli.h. I have to specialize the operator= member function of CComPtr 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.

        1 Reply Last reply
        0
        • M Mike Dimmick

          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. Using CComPtr with something that isn't a COM object will just confuse people. Stability. What an interesting concept. -- Chris Maunder

          R Offline
          R Offline
          Ray Gregory
          wrote on last edited by
          #4

          The class CFoo is a COM interface. It inherits multiply from, among other things, IDropSource and IDropTarget. In fact this is the reason I need to specialize the asignment operator for CComPtr<CFoo>. If I don't, then the compiler signals ambiguous conversions between CFoo* and IUnknown* because both IDropSource and IDropTarget derive from IUnknown. Unfortunately, the specialized copy asignment operator breaks in VS 2003 but not in VS 2002.

          B 1 Reply Last reply
          0
          • R Ray Gregory

            The class CFoo is a COM interface. It inherits multiply from, among other things, IDropSource and IDropTarget. In fact this is the reason I need to specialize the asignment operator for CComPtr<CFoo>. If I don't, then the compiler signals ambiguous conversions between CFoo* and IUnknown* because both IDropSource and IDropTarget derive from IUnknown. Unfortunately, the specialized copy asignment operator breaks in VS 2003 but not in VS 2002.

            B Offline
            B Offline
            Bo Hunter
            wrote on last edited by
            #5

            Could you show the lines that give the ambiguous conversion error? Thank You Bo Hunter

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups