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. error C2106: '=' : left operand must be l-value

error C2106: '=' : left operand must be l-value

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
5 Posts 4 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.
  • A Offline
    A Offline
    Aint
    wrote on last edited by
    #1

    hi. I have this error that pointed to this code: // Get a pointer to the current document CVector3DDoc * pDoc = GetDocument(); m_pLead.m_aValue = pDoc->m_aLead; // error occur here in view class Can I do this? m_aLead is a variable in Doc class while m_pLead is a variable in view class. both m_aLead and m_pLead.m_aValue is an array. I am trying to get the data in the Doc class to view class..Thanks.

    B J 2 Replies Last reply
    0
    • A Aint

      hi. I have this error that pointed to this code: // Get a pointer to the current document CVector3DDoc * pDoc = GetDocument(); m_pLead.m_aValue = pDoc->m_aLead; // error occur here in view class Can I do this? m_aLead is a variable in Doc class while m_pLead is a variable in view class. both m_aLead and m_pLead.m_aValue is an array. I am trying to get the data in the Doc class to view class..Thanks.

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      What you need to do to copy those depends on what kind of arrays you have. If they are of type CArray or similar, there is a member function CArray::Copy to achieve this. Others require you go through and copy each element in the array to a corresponding index on the destination array. However, if it's an array of pointers, you want to think this through carefully and understand who points to what an who is reponsible for resource cleanup so you don't dangle pointers later on. In a nutshell, the assignment operator = is usually not used to copy arrays.

      A 1 Reply Last reply
      0
      • A Aint

        hi. I have this error that pointed to this code: // Get a pointer to the current document CVector3DDoc * pDoc = GetDocument(); m_pLead.m_aValue = pDoc->m_aLead; // error occur here in view class Can I do this? m_aLead is a variable in Doc class while m_pLead is a variable in view class. both m_aLead and m_pLead.m_aValue is an array. I am trying to get the data in the Doc class to view class..Thanks.

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        If it is a normal language array such as char lead[10], then the compiler does not generate the code to copy for you. If you where expecting dynamic copy and or creation, then you need to use a container class like vector for that.

        char a1[10] = {/*something*/};
        char a2[10];

        memcpy(a2,a1,10); // copy 10 bytes from a1 to a2

        Or with vector

        std::vector b1;
        std::vector b2;
        /* assign something to b1
        ** ....
        */

        b2 = b1; // allocates memory (if needed) and copies b1 to b2

        INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

        1 Reply Last reply
        0
        • B bob16972

          What you need to do to copy those depends on what kind of arrays you have. If they are of type CArray or similar, there is a member function CArray::Copy to achieve this. Others require you go through and copy each element in the array to a corresponding index on the destination array. However, if it's an array of pointers, you want to think this through carefully and understand who points to what an who is reponsible for resource cleanup so you don't dangle pointers later on. In a nutshell, the assignment operator = is usually not used to copy arrays.

          A Offline
          A Offline
          Arman S
          wrote on last edited by
          #4

          In a nutshell, the assignment operator = is usually not used to copy arrays. Why do you think so? operator = is usual and natural for a concrete entity as far as the term 'assignment' itself is natural. An array may be assigned to another one which I think is natural [I'm not speaking about the correct ways of doing that]. For instance, std::vector has the = operator overloaded which, I'm pretty sure, is used extensivelly.

          -- ===== Arman

          B 1 Reply Last reply
          0
          • A Arman S

            In a nutshell, the assignment operator = is usually not used to copy arrays. Why do you think so? operator = is usual and natural for a concrete entity as far as the term 'assignment' itself is natural. An array may be assigned to another one which I think is natural [I'm not speaking about the correct ways of doing that]. For instance, std::vector has the = operator overloaded which, I'm pretty sure, is used extensivelly.

            -- ===== Arman

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            Good point. I don't use STL so I wasn't aware of that. Would it be safe to say the assignment operator is not usually used to copy arrays unless your using STL and a vector?

            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