Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Expr_node {
- friend std::ostream& operator << (std::ostream& lhs, const Expr_node& rhs) ;
- protected:
- virtual void print(std::ostream&) const = 0 ;
- virtual ~Expr_node() {}
- };
- std::ostream& operator << (std::ostream& lhs, const Expr_node& rhs) {
- rhs.print( lhs ) ;
- return lhs ;
- }
- class Int_node: public Expr_node {
- // friend class Expr;
- public :
- int n ;
- Int_node(int k): n(k) {}
- void print(std::ostream& o) const {
- o << n;
- }
- };
- int main() {
- Int_node n(1) ;
- operator<<( std::cout, n );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement