Этот код доставляет мне много головной боли при компиляции в GCC ARM.Я прекрасно использую его с компилятором MSVC ++ 2010. Я получаю ошибки компиляции, такие как:
Ошибка 1: ошибка ожидаемая ';'до 'i' C: \ Users \ Ryan \ Desktop \ droplets \ source \ MultiList.h 62
Почему мой шаблонный код не скомпилируется с использованием GCC?
#ifndef MULTILIST_H
#define MULTILIST_H
#include <list>
#include <fstream>
using namespace std;
/*
A list of lists
*/
template <typename E>
class MultiList {
protected:
list<list<E>*> m_lists;
list<E> *m_pCurrList;
public:
MultiList();
~MultiList();
/*
Starts a new list internally, given the first element
*/
void BeginNewList(E firstElement);
/*
Adds an element to the current list
*/
void AddElement(E newElement);
/*
Removes a given element from it's place in one of the lists,
splitting that list into two lists internally.
*/
void RemoveElement(E element);
/*
Returns a list of all element lists
*/
list<list<E>*> *GetLists() {
return &m_lists;
};
/*
Return the list that's currently being populated with AddElement()
*/
list<E>* GetCurrentList() {
return m_pCurrList;
};
};
template<typename E>
MultiList<E>::MultiList() {
m_pCurrList = NULL;
}
template<typename E>
MultiList<E>::~MultiList() {
for(list<list<E>*>::iterator i = m_lists.begin(); i != m_lists.end(); i++) {
list<E>::iterator j;
for(j = (*i)->begin(); j != (*i)->end(); j++) {
SDELETE(*j)
}
SDELETE(*i)
}
}
/*
Starts a new list internally, given the first element
*/
template<typename E>
void MultiList<E>::BeginNewList(E firstElement) {
list<E> *newlist = new(list<E>);
newlist->push_back(firstElement);
m_lists.push_back(newlist);
m_pCurrList = newlist;
}
/*
Adds an element to the current list
*/
template<typename E>
void MultiList<E>::AddElement(E newElement) {
m_pCurrList->push_back(newElement);
}
/*
Removes a given element from it's place in one of the lists,
splitting that list into two lists internally.
*/
template<typename E>
void MultiList<E>::RemoveElement(E element) {
list<E>* found = NULL;
list<E>::iterator foundIT = NULL;
// find which list 'element' is in
for(list<list<E>*>::iterator i = m_lists.begin(); i != m_lists.end(); i++) {
list<E>::iterator j;
for(j = (*i)->begin(); j != (*i)->end(); j++) {
E listElement = (*j);
if(listElement == element) {
found = (*i);
foundIT = j;
break;
}
}
if (j != (*i)->end()) break; // we breaked out of the inner loop
}
// now erase it and split the list
if (found) {
list<E>::iterator next = found->erase(foundIT);
list<E> *newlist = new(list<E>);
m_lists.push_back(newlist);
newlist->splice(newlist->begin(), *found, next, found->end());
SDELETE(element)
}
}
#endif