I am reading book and there is something I am not 100% sure and need a clarification.
this is extract from book:
"...Once you have placed a pure virtual function in the base class, you must override it in all the derived classes from which you want to instantiate objects. If class doesn't override the pure virtual function, it becomes an abstract class itself, and you can't instantiate objects from it. For consistency you may want to make all the virtual functions in the base class pure."
My question is if derived class Derived1 have function show() then it does override and it will not become abstract class.
What if (does this make sense?) Dervied1 have no such function like show()
but show1()??
#include <iostream>
class Base // base class
{
public:
virtualvoid show() = 0; // this is PURE virtual function
};
class Derived1 : public Base // derived class 1
{
public:
void show()
{
std::cout << "Derived1 " << std::endl; //this will be executed this time
}
};
class Derived2 : public Base
{
public:
void show()
{
std::cout << "Derived2 " << std::endl; //this will be executed this time
}
};
int main() {
//Base bad; // this is not going to work due to fact that BAD object is from PURE virtual class
Base* array[2]; // array of pointers to base class
Derived1 derived1;
Derived2 derived2;
array[0] = &derived1;
array[1] = &derived2;
array[0]->show(); // execute show in both objects
array[1]->show();
system("pause");
return 0;
}
> What if (does this make sense?) Dervied1 have no such function like show() but show1()??
call it `slartibartfast()' if you want, it's another function.