#include template class ListNode { private: T* hd; ListNode* tl; public: ListNode(T * head, ListNode * tail) : hd(head), tl(tail) {} T* head() { return hd; } ListNode* tail() { return tl; } }; class Whale { public: int len; Whale(int length) : len(length) {} int add(Whale * other) { return len + other->len; } }; template T sum_good(ListNode * list) { return *(list->head()) + sum_good(list->tail()); } template Elem sum(List* list) { if (list == NULL) return Elem(0); else return *(list->head()) + sum(list->tail()); } template int length(List* list) { if (list == NULL) { return 0; } else { return 1 + length(list->tail()); } } int length(double x) { return int(x - 10); } class A { public: double tail() { return 10.0; } }; int main() { // Whale * orca = new Whale(10); // ListNode * node = new ListNode(orca, NULL); ListNode * nums = new ListNode(new int(10), new ListNode(new int(30), NULL)); int val = sum< int, ListNode >(nums); cout << val << endl; A my_a; int result = length(&my_a); cout << result << endl; return 0; }