fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. struct WrongType : public std::runtime_error {
  6. WrongType(const char* msg) :runtime_error{msg} {}
  7. };
  8.  
  9. class Value {
  10. public:
  11. enum class Type {
  12. NUMBER, STRING, ARRAY, OBJECT
  13. };
  14.  
  15. virtual Type type() const =0;
  16. double& number() { throw WrongType {"Not a number"}; } // fat
  17. };
  18.  
  19. class NumberValue : public Value {
  20. double n;
  21. public:
  22. NumberValue(double x) :n{x} {}
  23.  
  24. Type type() const override { return Value::Type::NUMBER; }
  25. double& number() { return n; }
  26. };
  27.  
  28. int main() {
  29. return 0;
  30. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty