Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Expr_node {
  4.     friend std::ostream& operator << (std::ostream& lhs, const Expr_node& rhs) ;
  5.  
  6.   protected:
  7.     virtual void print(std::ostream&) const = 0 ;
  8.     virtual ~Expr_node() {}
  9. };
  10.  
  11. std::ostream& operator << (std::ostream& lhs, const Expr_node& rhs) {
  12.     rhs.print( lhs ) ;
  13.     return lhs ;
  14. }
  15.  
  16. class Int_node: public Expr_node {
  17.     // friend class Expr;
  18.   public :
  19.     int n ;
  20.  
  21.     Int_node(int k): n(k) {}
  22.     void print(std::ostream& o) const {
  23.         o << n;
  24.     }
  25. };
  26.  
  27. int main() {
  28.     Int_node n(1) ;
  29.     operator<<( std::cout, n );
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement