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