fork download
  1. //#include<iostream>
  2. using namespace std;
  3. #include<string>
  4.  
  5. class Expr{};
  6. class NumExpr : public Expr {
  7. public:
  8. NumExpr( string v );
  9. string name();
  10. private:
  11. int number;
  12. friend ostream& operator<<(ostream &s, const NumExpr &num);
  13. };
  14.  
  15. NumExpr::NumExpr( string n ) {
  16. number = 10;
  17. }
  18. string NumExpr::name() {
  19. return "num";
  20. }
  21. ostream & operator<<(ostream &s, const NumExpr &num) {
  22. s << num.number;
  23. return s;
  24. }
  25. int main()
  26. {
  27. //NumExpr obj("hello");
  28. //cout<<obj;
  29.  
  30.  
  31. return 0;
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘std::ostream& operator<<(std::ostream&, const NumExpr&)’:
prog.cpp:22: error: no match for ‘operator<<’ in ‘s << num->NumExpr::number’
prog.cpp:21: note: candidates are: std::ostream& operator<<(std::ostream&, const NumExpr&)
stdout
Standard output is empty