Tell me how to fix the following error:
There is a data structure:
struct CMyData { int m_data; }; There is a constant pointer to this structure.
const CMyData* ptr = _get(); I want to write to another structure a pointer to the data from the first
myData2.m_ptr = &ptr->m_data; And I get an error
error C2440: '=': cannot convert from 'const CMyData :: int *' to 'CMyData :: int *'
Corrected by abolishing the constant, i.e. So:
CMyData* ptr = _get(); But I want to adhere to the minimum functionality - I'm not going to change the ptr itself, that's why I declared it a constant.
m_ptrfield not asint*, but asconst int *... - Harryconst CMyData* ptris not a "constant pointer", but a "pointer to a constant structure" - Fat-Zerconstbelonged to another part. - Zhihar 2:53