What is the difference between:
a)
class base{
int a;
public:
virtual int function();
};
class derived : public base{
int b;
public:
int function();
};
b)
class base{
int a;
public:
int function();
};
class derived : public base{
int b;
public:
int function();
};
Why would you use (a) and why would you use (b)?
Is (b) a kind of polymorphism?
a) overrides the method in the base class. b) hides it. b) is not polymorphism.
Here’s a useful link: The Definitive C++ Book Guide and List