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. C / C++ / MFC
  4. VC++ 6 to VS 2005 Porting problem.

VC++ 6 to VS 2005 Porting problem.

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++visual-studiographicstutorial
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.
  • E Offline
    E Offline
    Eurosid
    wrote on last edited by
    #1

    I'm porting a legacy app. This code was fine in VC6, but VS2005 doesn't like it: struct CColumnBool { std::vector m_vBoolData; CColumnBool() { m_vBoolData.clear(); }; bool& operator[](UINT uiRow) { return m_vBoolData[uiRow]; // <--- error on this line... }; const bool& operator[](UINT uiRow) const { return m_vBoolData[uiRow]; }; }; The error is this: error C2440: 'return' : cannot convert from 'std::_Vb_reference<_MycontTy>' to 'bool &' with [ _MycontTy=std::vector> ] The weird thing is that this code does NOT generate the same error: struct CColumnInt { std::vector m_vIntData; CColumnInt() { m_vIntData.clear(); }; int& operator[](UINT uiRow) { return m_vIntData[uiRow]; }; const int& operator[](UINT uiRow) const { return m_vIntData[uiRow]; }; }; C2440 is a type conversion error, of course. MSDN lists several causes for this, but I don't see where they apply. Any ideas how to fix this?

    N M 2 Replies Last reply
    0
    • E Eurosid

      I'm porting a legacy app. This code was fine in VC6, but VS2005 doesn't like it: struct CColumnBool { std::vector m_vBoolData; CColumnBool() { m_vBoolData.clear(); }; bool& operator[](UINT uiRow) { return m_vBoolData[uiRow]; // <--- error on this line... }; const bool& operator[](UINT uiRow) const { return m_vBoolData[uiRow]; }; }; The error is this: error C2440: 'return' : cannot convert from 'std::_Vb_reference<_MycontTy>' to 'bool &' with [ _MycontTy=std::vector> ] The weird thing is that this code does NOT generate the same error: struct CColumnInt { std::vector m_vIntData; CColumnInt() { m_vIntData.clear(); }; int& operator[](UINT uiRow) { return m_vIntData[uiRow]; }; const int& operator[](UINT uiRow) const { return m_vIntData[uiRow]; }; }; C2440 is a type conversion error, of course. MSDN lists several causes for this, but I don't see where they apply. Any ideas how to fix this?

      N Offline
      N Offline
      Nougat H
      wrote on last edited by
      #2

      This may help perhaps: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1354391&SiteID=1[^]

      E 1 Reply Last reply
      0
      • N Nougat H

        This may help perhaps: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1354391&SiteID=1[^]

        E Offline
        E Offline
        Eurosid
        wrote on last edited by
        #3

        Adis H. wrote:

        This may help perhaps: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1354391&SiteID=1\[^\]

        Yes, that's it exactly. Thanks! :-D

        1 Reply Last reply
        0
        • E Eurosid

          I'm porting a legacy app. This code was fine in VC6, but VS2005 doesn't like it: struct CColumnBool { std::vector m_vBoolData; CColumnBool() { m_vBoolData.clear(); }; bool& operator[](UINT uiRow) { return m_vBoolData[uiRow]; // <--- error on this line... }; const bool& operator[](UINT uiRow) const { return m_vBoolData[uiRow]; }; }; The error is this: error C2440: 'return' : cannot convert from 'std::_Vb_reference<_MycontTy>' to 'bool &' with [ _MycontTy=std::vector> ] The weird thing is that this code does NOT generate the same error: struct CColumnInt { std::vector m_vIntData; CColumnInt() { m_vIntData.clear(); }; int& operator[](UINT uiRow) { return m_vIntData[uiRow]; }; const int& operator[](UINT uiRow) const { return m_vIntData[uiRow]; }; }; C2440 is a type conversion error, of course. MSDN lists several causes for this, but I don't see where they apply. Any ideas how to fix this?

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

          std::vector<bool> is not based on an array of bool. Instead the bits are packed, and as such it is impossible to take the address of any given bit, or create a reference to it. Instead operator[] has to return a proxy class. This is a specialization of the vector template required by the C++ standard. This is widely considered to be a massive error in the standard. Unfortunately it is required, in order to claim conformance to the standard.

          Stability. What an interesting concept. -- Chris Maunder

          E 1 Reply Last reply
          0
          • M Mike Dimmick

            std::vector<bool> is not based on an array of bool. Instead the bits are packed, and as such it is impossible to take the address of any given bit, or create a reference to it. Instead operator[] has to return a proxy class. This is a specialization of the vector template required by the C++ standard. This is widely considered to be a massive error in the standard. Unfortunately it is required, in order to claim conformance to the standard.

            Stability. What an interesting concept. -- Chris Maunder

            E Offline
            E Offline
            Eurosid
            wrote on last edited by
            #5

            Mike Dimmick wrote:

            This is widely considered to be a massive error in the standard.

            I would think so. Thanks for the explanation.

            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