网游之无法无天,幼年记事簿txt,君主的太阳
编译方法:g++ -g template_main.cpp
============分割线==========================
#include <iostream> using namespace std; template<typename a> class list; //节点 template<typename a> class listnode{ friend class list<a>; public: listnode():data(a()), next(null){} listnode(a a, listnode *n) : data(a), next(n){} private: a data; listnode *next; }; //单链表 template<typename a> class list{ public: list(); //尾插 bool push_back(a val); //显示链表 void show()const{ listnode<a> *n = first->next; while(null != n){ cout << n->data; n = n->next; } cout << "null" << endl; } private: listnode<a> *first; listnode<a> *last; size_t size; }; template<typename t> list<t>::list(){ first = last = new listnode<t>; last->next = null; size = 0; } //尾插 template<typename a> bool list<a>::push_back(a value){ listnode<a> *node = new listnode<a>; if(null == node) return false; node->data = value; node->next = null; last->next = node; last = node; size++; return true; } //显示链表 /* template<typename a> void list<a>::show()const{ listnode<a> *n = first->next; while(null != n){ cout << n->data; n = n->next; } cout << "null" << endl; } */ class value{ friend ostream& operator<<(ostream &o, const value &v); public: value(int d = 0) : value(d){} private: int value; }; ostream& operator<<(ostream &o, const value &v){ o << v.value << "->"; return o; } int main(){ list<value> l; for(int i = 0; i < 10; ++i){ l.push_back(value(i)); } l.show(); }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论