WAP to show the working of abstract class by considering suitable example
#include <iostream>
struct Abstract {
virtual void Print(int x) = 0;
};
struct Quoted: Abstract {
void Print(int x) {
std::cout << "\""<< x << "\"" << '\n';
}
};
struct Arrowed: Abstract {
void Print(int x) override {
std::cout << "->" << x << '\n';
}
};
int main() {
Abstract * a = new Quoted(), *b = new Arrowed();
a->Print(1);
b->Print(1);
delete a, b;
return 0;
}
Comments
Leave a comment