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 8893779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:19:58+00:00 2026-06-14T23:19:58+00:00

#include <iostream> #include <string> using namespace std; template <class T> class Node{ friend class

  • 0
#include <iostream>
#include <string>

using namespace std;

template <class T>
class Node{
        friend class LinkedList<T>;
private:
    T data;
    Node <T> *next;
public:
    Node();
    Node(T d);
    ~Node();
};

template <class T>
Node<T>::Node(){
    T data = 0;
    next = 0;
}

template <class T>
Node<T>::Node(T d){
    data = d;
    next = 0;

}

template<class T>
Node<T>::~Node(){
    delete next;
}

template <class T>
class LinkedList{
private: 
    Node <T> *head;
public:
    LinkedList();
    ~LinkedList();
    void Push_Front(const T& e);
}

template<class T>
LinkedList <T>::LinkedList(){
    head = 0;
}

template <class T>
LinkedList<T>::~LinkedList(){
    delete head;
}

template <class T>
void LinkedList<T>::Push_Front(const T &e){
    Node<T> *newNode = new Node<T>(e);

    if(head == 0)
        head = new Node<T>(e);

    newNode->next = head;
   head = newNode;
}


void main(){
    LinkedList<int> list;

    list.Push_Front(10);


    int t;
    cin>>t;
    return ;
}

I am trying to write a template version of linked list. I ran into some errors and unsure why. The error occurs when I try to make friend class LinkedList, I need to do this so I can access T data from LinkedList.

: error C2059: syntax error : '<'
: see reference to class template instantiation 'Node<T>' being compiled
: error C2238: unexpected token(s) preceding ';'
: error C2143: syntax error : missing ';' before 'template'
: error C2989: 'LinkedList' : class template has already been declared as a non-class template
: see declaration of 'LinkedList'
: 'LinkedList': multiple template parameter lists are not allowed
: error C2988: unrecognizable template declaration/definition
: error C2059: syntax error : '<'
: error C2588: '::~LinkedList' : illegal global destructor
: fatal error C1903: unable to recover from previous error(s); stopping compilatio
  • 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-14T23:20:00+00:00Added an answer on June 14, 2026 at 11:20 pm

    You’re missing a semicolon at the end of your class definition for LinkedList. However, even if you fix that, since Node<T> needs to know about LinkedList<T> and vice versa, you’ll need to declare them up the top:

    #include <iostream>
    #include <string>
    
    using namespace std;
    
    template <typename T> class Node;
    template <typename T> class LinkedList;
    
    //Code as before
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class
I have this in furniture.h: #include <iostream> #include <string> using namespace std; class Furniture
Having a program like this: #include <iostream> #include <string> using namespace std; class test
I have the class Furniture with: Furniture.h: #include <iostream> #include <string> using namespace std;
In the sample: #include <iostream> using namespace std; class B { public: virtual void
I have the following code: #include <iostream> #include <stdio.h> using namespace std; template <class
The code in c++ is as follows: #include<iostream> #include<string> #include<set> using namespace std; class
For the following code: #include <map> #include <iostream> #include <string> using namespace std; template
#include <iostream> using namespace std; template<class T> void toBinary(T num) { char * numi
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;

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.