Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Copying values from base class to derived class

Didnt want to put a really long title, continuing – without modifying the base class and without copying one by one.

Lets say the base is CClient, but I dont want to add or remove anything:

class CClient
{
public:
    void (*Connect)();
    void (*Disconnect)();

    bool m_bIsConnected;
};

And say this is derived CClientHook.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class CClientHook : public CClient
{
public:
    bool Setup(bool hook);

    bool m_bIsHooked;
};

How can I copy values from CClient object to CClientHook object safely? Sorry for weird wording.

EDIT: To clarify, there are two objects and no, Connect and Disconnect arent supposed to be methods.

CClient g_Client;
CClientHook g_ClientHook;

>Solution :

Given

CClient a;
CClientHook b;

There are at least two options:

  • static_cast<CClient &>(b) = a;
  • b.CClient::operator=(a);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading