下面这种定义方式会报错: Undefined symbols for architecture x86_64
templateclass longint{public: T num; longint (T a = 0) { num = a; } friend ostream& operator<< (ostream& out, const longint & Lint); ~longint (){ ; }private:};template ostream& operator<< (ostream &out, const longint & Lint) { return out<
改法一:将重载运算符的T改成S就行了
//类内声明时templatefriend ostream& operator<< (ostream& out, const longint & Lint);//类外定义时templateostream& operator<< (ostream &out, const longint & Lint) { return out<
改法二:直接在类内定义
friend ostream& operator<< (ostream& out, const longint& Lint) { return out<