Answer to Question #269173 in C++ for kool

Question #269173

WAP to show the working of abstract class by considering suitable example


1
Expert's answer
2021-11-21T17:34:25-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS