1 / 1 / 1
Регистрация: 29.08.2009
Сообщений: 63
|
|
1 | |
линковка шаблона05.09.2009, 08:47. Просмотров 1118. Ответов 1
Метки нет Все метки)
(
линковка шаблона
Код
#ifndef intrusive_list__HHHH #define intrusive_list__HHHH struct link_err { string s; link_err(const char* pc):s(pc){} }; struct slink { //base class for intrusive single linked list slink* next; slink(slink* p=0):next(p) {} }; template<class T> class intrusive_list { T *head; T *last; unsigned int s; // size_t s; public: class iterator { T* p; public: iterator(T* pp):p(pp) {} iterator& operator++(int ) { p=static_cast<T*>(p->next); return *this; } T& operator*() { return *p; } bool operator==(const iterator& i) { return p==i.p; } bool operator!=(const iterator& i) { return p!=i.p; } }; intrusive_list():head(0),last(0),s(0) {} iterator begin() { return iterator(head); } iterator end() { return iterator(0); } void push_front(T& t) ; void push_back(T& t) ; iterator& erase(iterator& i) { if (!s) throw link_err("empty error"); s--; if (!s) { head=last=0; return 0; } if ( head == i.p ) { head=i.p->next; i.p->next=0; i++; return i; } } }; template<class T> void intrusive_list<T>::push_front(T& t) { s++; t.next=head; if(! last) last=&t; head=&t; return; } template<class T> void intrusive_list<T>::push_back(T& t) { s++; if(! last) head=last=&t; else { last->next=&t; last=&t; } return; } #endif как вынести определения push_front,push_back,erase в отдельный translation unit?
0
|
|
05.09.2009, 08:47 | |
Линковка либов) Динамическая линковка Статическая линковка Линковка библиотек gcc под линукс |
|
![]() |
|
11.09.2009, 13:18 | 2 |
Реализацию шаблонов нужно писать в .h файле.
0
|
11.09.2009, 13:18 | |
Заказываю контрольные, курсовые, дипломные и любые другие студенческие работы здесь.
Gtest, доступ к элементам базового класса-шаблона без указания параметров шаблона. баг или фича? Определение метода-шаблона за пределами шаблона класса Линковка Qt 5.1.1 статическая линковка
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |