SHARE
TWEET

Untitled

a guest Jun 25th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top