fork download
  1. #include <iostream>
  2. #include <memory>
  3. #include <vector>
  4. #include <cstdint>
  5. using namespace std;
  6.  
  7. enum shape_kind {Cube, Sphere};
  8.  
  9. struct shape {
  10. virtual ~shape() {}
  11. virtual shape_kind kind() = 0;
  12. };
  13.  
  14. struct cube : public shape {
  15. shape_kind kind() { return Cube; }
  16. };
  17. struct sphere : public shape {
  18. shape_kind kind() { return Sphere; }
  19. };
  20.  
  21. shared_ptr<shape> parse(const vector<uint8_t> data) {
  22. if (data.at(0) == 1) {
  23. return shared_ptr<shape>(new sphere);
  24. } else {
  25. return shared_ptr<shape>(new cube);
  26. }
  27. }
  28.  
  29. int main() {
  30. vector<uint8_t> x {1};
  31. vector<uint8_t> y {2};
  32. auto s = parse(x);
  33. auto c = parse(y);
  34. cout << (*s).kind() << endl;
  35. cout << (*c).kind() << endl;
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1
0