C++ Abstraction OOP (Inherit only some method to derived class)

  abstraction, c++, c++17, inheritance, oop

Suppose i have a socket class:

class Socket{
public:
    ... Some Code ...
    Socket(int type){
         isServer = type;
        //some code
    }
    virtual void Send(string s);
    virtual void Send(string s, int clientID);
    ... Some Code ...
private:
    int isServer;
};

This is to be used both as a server and client.

Now I need to have 2 Derived classes:

class ClientSocket : public Socket{
public:
    ... Some Code ...
};

class ServerSocket : public Socket{
public:
    ... Some Code ...
};

What I want is that ClientSocket will only have access to Send(string) and server socket will only have access to Send(string, int)

I checked some other answer:

And that has a good idea of not using inheritance at all rather just encapsulate(Have a socket instance in server). But I want to know whether this can be done using Inheritance.

Source: Windows Questions C++

LEAVE A COMMENT