VC ++ error C2248: "CObject: CObject": private Members cannot be accessed (declared in the "CObject" class), c2248cobject
This error often occurs when you use classes such as CArray or CList.
This error is caused
There is an operation such as Add (). In this operation, a = operation is actually required, but this = operation is not implemented in the Custom class. Therefore, the program automatically goes to its parent class, that is, the CObject class, but finds the = of this class is a private, so this error is reported.
After knowing the cause, the solution will naturally be available, that is, the error will disappear after the overload operator = overload in the Custom class.
Class COptRect: public CObject {public: COptRect (); virtual ~ COptRect (); // The start range of the operation: CRect m_OptStartRect; // The end range of the operation: CRect m_OptEndRect; // The target interface of the operation: int m_OptDesSurface; COptRect & operator = (COptRect & src );};
Implementation Code
COptRect::COptRect() : m_OptDesSurface(0){}COptRect::~COptRect(){}COptRect& COptRect::operator = (COptRect & src){ this->m_OptDesSurface = src.m_OptDesSurface; this->m_OptEndRect = src.m_OptEndRect; this->m_OptStartRect = src.m_OptStartRect; return *this;}
Then, after implementing this custom class, start to use it.
First define the variable array
CArray<COptRect, COptRect&> optArray;
After this array, we use a command to add new elements.
// Add an operation region void CSurface: AddOptRect (CRect Start, CRect End, int DesID) {COptRect ort; ort. m_OptStartRect = Start; ort. m_OptEndRect = End; ort. m_OptDesSurface = DesID; optArray. add (ort );}After this operation, the following error will not be reported! Problem Solving