VC + + Error C2248: "Cobject::cobject": Cannot access private member (declared in "CObject" Class)

Source: Internet
Author: User

This error often occurs when using classes such as: CArray or CList.

The cause of this error is due to the custom class's array entry

There is an operation like ADD () in this operation, actually need a = operation, but this = operation is not implemented in the custom class, so, the program automatically go to its parent class is the CObject class to find, but found a class of this = is a private then reported this A mistake.

Knowing the cause of the solution is natural, that is, in the custom class overloaded operator = overload after this error is gone.

class  Public cobject{public:    coptrect ();     virtual ~coptrect ();     // start range of the Operation     CRect m_optstartrect;     // end range of the Operation     CRect m_optendrect;     // Target Interface    of the operation int M_optdessurface;    Coptrectoperator = (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;}

So after implementing this custom class, start using it

Define the array of variables first

Carray<coptrect, coptrect&> Optarray;

After this array, we use a command that adds a new element

// add an action area to the interface void int Desid) {    coptrect ort;     = Start;     = End;     = Desid;    Optarray.add (ORT);}
After doing so, do not report the above error! Problem solving

VC + + Error C2248: "Cobject::cobject": Cannot access private member (declared in "CObject" Class)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.