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

  • Home
  • SEARCH
  • 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 8879641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:59:36+00:00 2026-06-14T19:59:36+00:00

I’ve been working on a linked list template class to do the same thing

  • 0

I’ve been working on a linked list template class to do the same thing with a variety of variables, and managed to sort out most of the issues. Except when I compile, I get these:

g++ -Wall -o template_test template_test.cpp
In file included from template_test.cpp:1:0:
LinkedList.h:50:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:51:30: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:56:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:57:51: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:92:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:93:31: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:102:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:103:34: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:119:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:120:48: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:158:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:159:37: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:193:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:194:34: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
LinkedList.h:210:11: error: declaration of ‘class Type’
LinkedList.h:7:11: error:  shadows template parm ‘class Type’
LinkedList.h:211:34: error: invalid use of incomplete type ‘class LinkedList<Type>’
LinkedList.h:8:7: error: declaration of ‘class LinkedList<Type>’
make: *** [template_test] Error 1

It pretty much says the same thing for every template function I have. Can anyone decipher for me what these messages mean, what is causing the compiler to throw these messages, and how do I fix this? I’ll be rereading, and possible rewriting my code in the meantime.
My code is as follows:

#include <string>
#include <iostream>
using namespace std;

template <class Type>
class LinkedList{
public:

 * default constructor and a copy constructor that creates a copy
 * of the given object*/
LinkedList(); //default construtor
LinkedList(const LinkedList& lst); //copy constructor
~LinkedList();//destructor

void add(Type data);

void insertAt(int pos, Type data);

bool remove(Type data );

void removeAll();

void printList();

template <class Type>
LinkedList<Type>::LinkedList(){
head = NULL;
size = 0; //Don't forget to do this!!!
}

template <class Type>
LinkedList<Type>::LinkedList(const LinkedList& lst){
if (lst.head == NULL){
    head = NULL;
    size = 0;
}
else{
    head = new Node;
    head->data = lst.head->data;
    Node *pNewNode = head;
    Node *pOldNode = lst.head->next;
    while (pOldNode != NULL){
        pNewNode->next = new Node;
        pNewNode = pNewNode->next;
        pNewNode->data = pOldNode->data;;
        pOldNode = pOldNode->next;
    }
    pNewNode->next = NULL;
    size = lst.size;
}
}

template <class Type>
LinkedList<Type>::~LinkedList(){
    removeAll();
}

template <class Type>
void LinkedList<Type>::add(Type x){
Node *p = new Node; //temporary node
// Assign appropriate values to the new node
p -> data = x;
p -> next = head;
// Make the head point to the new node
head = p;   
size++;
}

template <class Type>
void LinkedList<Type>::insertAt(int pos, Type x){
Node *p;
Node *newNode;

// Check that pos is a valid index
if (pos <= size){
    newNode = new Node; //new node
    newNode->data = x;

    // Deal with case when item is to be inserted at the head of the list
    if (pos == 0){
        newNode->next = head;
        head = newNode;
    }// if(pos == 0)
    else{
        p = head;
        // Move to position BEFORE insertion point
        for(int i = 0; i < pos-1; i++){
            // Check that p points to a node
            // Note using exception handling should throw an exception         
            if(p == NULL){
                return;
            }
            p = p->next;
        }//for
        // Insert node
        newNode->next = p->next;
        p->next = newNode;
    }//else (pos != 0)
    size++;
}//else (pos >= size) do nothing
}

template <class Type>
bool LinkedList<Type>::remove(Type x){
Node *p = head;
Node *temp;
if (head == NULL){
    return false;
}
else if (head->data == x){
    head = head->next;
    delete p; //currently assigned head
    size--;
    return true;
}
else{
    while(p->next != NULL){
        // Check next node for target
        if(p->next->data == x){
            temp = p->next;
            p->next = p->next->next;
            delete temp;
            return true;
        }
        p = p->next;
    }
}
return false;
}

template <class Type>
void LinkedList<Type>::removeAll(){
Node *p = head;
// Traverse the list deleting nodes
while (p!= NULL){
    head = head->next; // Mustn't "lose" the next node
    delete p; // De-allocate memory
    p = head; // Go to next node
}
head = NULL;
size = 0;
}

template <class Type>
void LinkedList<Type>::printList(){
Node *p = head;
cout << "["; //Nice format!
// Traverse the list
while (p != NULL){
    cout << p -> data; // Print data
    p = p -> next; // Go to next node
    if (p != NULL){
        cout << ","; // Print a comma unless at the end of the list
    }
}
cout << "]"; // Don't print a newline - it might not be wanted
}


private:
struct Node {
    Type data; //list data
    Node *next; //pointer to next item in the list
};

Node *head; //Pointer to the first node in the list
int size; //Records the number of nodes in the list
};
  • 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-14T19:59:37+00:00Added an answer on June 14, 2026 at 7:59 pm

    You are using the syntax to define a member function outside of the scope of a class inside a class. This doesn’t work.

    This should do it:

    template<typename X>
    class Foo {
    public:
      void f();
    }; // notice end of class scope here
    
    template<typename X>
    void Foo<X>::f() {
      // impl
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you

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.