// BAD usage (Java style)
class Point2d {
public:double getX();double getY();void setX(double);void setY(double);
private:double x;double y;};// This just makes code more complicated and error prone (possibly slower too).// Good usage
class FileHandler {
public:
read();
write();
FILE * getNative(){return handler;}
private:// FILE is windows only! Don't use it in your real code :-)
FILE * handler;};// This just returns a handler to a native resource that could be useful to other users, beside what you have coded in "read()" and "write()"// This way users can use the native handler to extend functionality

Sometimes you may need to instantiate objects of different types during program execution, each exposing the same interface. This is called runtime polymorphism.
If that’s the case go with inherithance and std::unique_ptr or std::shared_ptr.
Still remember that runtime polymorphism should not be used as a default, since it’s more complicated and costs CPU time