Last active
June 24, 2017 14:54
-
-
Save chenhong805/45b135872fde10709df9c6490beddd9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
class Node { | |
protected: | |
T val; | |
virtual T getVal() { return this.val; } | |
virtual void setVal(T val) { this.val = val; } | |
template <typename R, typename V> | |
virtual Node<R> operator+(Node<V> rhs); | |
} | |
class DoubleNode: public Node<double> { | |
virtual DoubleNode operator+(DoubleNode n){ | |
return new DoubleNode( this.getVal() + n.getVal() ); // handle double + double | |
} | |
virtual DoubleNode operator+(IntNode n){ | |
return new DoubleNode( this.getVal() + n.getVal() ); // handle double + int | |
} | |
} | |
class IntNode: public Node<int> { | |
virtual DoubleNode operator+(DoubleNode n) { | |
// implementation | |
} | |
virtual IntNode operator+(IntNode n) { | |
// implementation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment