fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. class NumExpr {
  8. public:
  9. NumExpr( string v );
  10. string name();
  11. private:
  12. int number;
  13. friend ostream& operator<<(ostream &s, const NumExpr &num);
  14. };
  15.  
  16. NumExpr::NumExpr( string n ) {
  17. number = atoi( n.c_str() );
  18. }
  19. string NumExpr::name() {
  20. return "num";
  21. }
  22. ostream & operator<<(ostream &s, const NumExpr &num) {
  23. s << num.number;
  24. return s;
  25. }
  26.  
  27. int main(){
  28.  
  29. NumExpr e("10");
  30. std::cout<<e;
  31. }
  32.  
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
10