Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7882393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:16:26+00:00 2026-06-03T04:16:26+00:00

I’m writing my own template list class with iterator, and have this error((( compiler:GCC

  • 0

I’m writing my own template list class with iterator, and have this error(((
compiler:GCC from MinGW( i use Eclipse IDE )
my code:
cpp:

#include <iostream>
#include "tlist.h"
using namespace std;
int main(){
  return 0;
}

header

template<typename T>
class element{
private:
    element<T>* pre;
    element<T>* next;
    T data;
public:
    element(){};
    ~element(){};
    element(T d){
        pre=NULL;
        next=NULL;
        data=d;
    }
    void SetPre(element<T>* a){
        pre=a;
    };
    void SetNext(element<T>* a){
        next=a;
    };
    void SetData(T d){
        data=d;
    }
    element<T>* GetPre(){
        return pre;
    }
    element<T>* GetNext(){
        return next;
    }
    T GetData(){
        return data;
    }
};
template<typename T>
class Tlist{
private:
    element<T>* first;
    element<T>* last;
    int size;
public:
        int GetSize(){
        return size;
    }
        Tlist(){
        first=NULL;
        last=NULL;
        size=0;
    }
        ~Tlist(){};
        Tlist(T d){
        element<T>* tmp;
        tmp->SetPre(NULL);
        tmp->SetNext(NULL);
        tmp->SetData(d);
        this->size=1;
        this->first=tmp;
        this->last=tmp;
                }
    class Iterator{
    private:
        element<T>* pointing;
    public:
        Iterator(){
            pointing=NULL;
        };
        ~Iterator(){};
        Tlist<T>::Iterator& operator++(int i);
        element<T>* operator*();
        Iterator(element<T>* b){
            pointing=b;
        }
    };
    bool empty();
    void clear();
    void swap(Tlist<T>& lst);
    Tlist<T>::Iterator begin();
    Tlist<T>::Iterator end();
    T front();
    T back();
    void push_back(T t);
    void push_front(T t);
    void pop_front();
    void pop_back();
    Tlist<T>::Iterator insert(Tlist<T>::Iterator pos,T data);
    Tlist<T>::Iterator erase(Tlist<T>::Iterator pos);
    void splice(Tlist<T>::Iterator pos,Tlist<T>* in);
    Tlist<T> operator=(Tlist<T> const &other){
    this->size=other.size;
    this->first=other.first;
    this->last=other.last;
    return *this;
};
};
template<typename T>
Tlist<T>::Iterator& Tlist<T>::Iterator::operator++(int i){
    element<T>* temp=*this;
    if(temp->GetNext()!=NULL) this->pointing=temp->GetNext();
    return *this;
}
template<typename T>
element<T>* Tlist<T>::Iterator::operator*(){
    return pointing;
}
template<typename T>
bool Tlist<T>::empty(){
            if(this->size==0) return true;
            else return false;
};
template<typename T>
void Tlist<T>::clear(){
            element<T>* son;
            element<T>* temp;
            son=this->first;
            while(son!=NULL){
                temp=son->next;
                delete son;
                son=temp;
            }
            this->size=0;
};
template<typename T>
void Tlist<T>::swap(Tlist<T>& lst){
            int temp=this->size;
            this->size=lst->size;
            lst->size=temp;
            Tlist<T>* tmp;
            *tmp=*this;
            *this=lst;
            lst=*tmp;
}
template<typename T>
Tlist<T>::Iterator Tlist<T>::begin(){
                Tlist<T>::Iterator res(this->first);
                return res;
};
 template<typename T>
Tlist<T>::Iterator Tlist<T>::end(){
                Tlist<T>::Iterator res(this->last);
                return res;
}
template<typename T>
T Tlist<T>::front(){
return this->first->GetData();
}
template<typename T>
T Tlist<T>::back(){
    return this->last->GetData();
};
template<typename T>
void Tlist<T>::push_front(T d){
    element<T>* temp(d);
    this->size++;
    this->first->SetPre(temp);
    temp->SetNext(this->first);
    this->first=temp;
}
template<typename T>
void Tlist<T>::push_back(T d){
    element<T>* temp(d);
    this->last->SetNext(temp);
    this->size++;
    temp->SetPre(this->last);
    this->last=temp;
}
template<typename T>
void Tlist<T>::pop_front(){
    element<T>* temp=this->first->GetNext;
    delete this->first;
    this->first=temp;
    this->size--;
}
template<typename T>
void Tlist<T>::pop_back(){
    element<T>* temp=this->last;
    delete this->last;
    this->last=temp;
    this->size--;
}
template<typename T>
Tlist<T>::Iterator Tlist<T>::insert(Tlist<T>::Iterator pos,T d){
    element<T>* temp(d);
    element<T>* p=*pos;
    element<T>* n=p->GetNext();
    p->SetNext(temp);
    temp->SetPre(p);
    if(n!=NULL){
        n->SetPre(temp);
        temp->SetNext(n);
    }
    this->size++;
    return pos++;
}
template<typename T>
Tlist<T>::Iterator Tlist<T>::erase(Tlist<T>::Iterator pos){
    if(pos==this->end()){
                    this->pop_back();
                    return this->end();
                }
    if(pos==this->begin()){
        this->pop_front();
        return this->begin();
    }
    else{
        element<T>* del=*pos;
        element<T>* p=del->GetPre();
        element<T>* n=del->GetNext();
        pos++;
        p->SetNext(n);
        n->SetPre(p);
        delete del;
        this->size--;
        return pos;
    }
 };
 template<typename T>
void Tlist<T>::splice(Tlist<T>::Iterator pos,Tlist<T>* a){
    this->size+=a->GetSize();
    element<T>* p=*pos;
    element<T>* n=p->GetNext();
    p->SetNext(a->first);
    a->first->SetPre(p);
    n->SetPre(a->last);
    a->last->SetNext(n);
    a->size=0;
    a->first=NULL;
    a->last=NULL;
}

and the errors are:

..\tlist.h:99: error: expected constructor, destructor, or type conversion before '&' token
..\tlist.h:136: error: expected constructor, destructor, or type conversion before 'Tlist'
..\tlist.h:141: error: expected constructor, destructor, or type conversion before 'Tlist'
..\tlist.h:184: error: expected constructor, destructor, or type conversion before 'Tlist'
..\tlist.h:198: error: expected constructor, destructor, or type conversion before 'Tlist'

help me, if you can, please

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:16:27+00:00Added an answer on June 3, 2026 at 4:16 am

    When you say

    Tlist<T>::anything
    

    the compiler first thinks you may mean some static variable of the class Tlist<T> called anything. In order to tell it you indicate a type, you should prepend the construct with typename:

    template<typename T>
    typename Tlist<T>::Iterator& TList<T>::Iterator::operator++(int){
    ...
    

    (edit: just bumped into an article on typename)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.