fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class speziell {
  5. struct allg {
  6. virtual double get() =0;
  7. };
  8. struct einfach0 : allg {
  9. double get() { return 0.0; }
  10. };
  11. struct interpoliert : allg {
  12. interpoliert(double x) : x(x) {}
  13. double x;
  14. double get() { return x; }
  15. };
  16. std::unique_ptr<allg> data;
  17. public:
  18. speziell() : data(new einfach0) {}
  19. speziell(double x) : data(new interpoliert(x)) {}
  20.  
  21. double get() { return data->get(); }
  22. };
  23.  
  24. int main()
  25. {
  26. speziell a;
  27. speziell b(4.0);
  28.  
  29. std::cout << a.get() << ' ' << b.get() << std::endl;
  30. }
  31.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0 4