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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:33:52+00:00 2026-05-31T19:33:52+00:00

I’m trying to create my own templated List class as a practice excercise. I

  • 0

I’m trying to create my own templated List class as a practice excercise. I should have probably started smaller but there you go.. i’m getting the error “expected unqualified-id before ‘<‘ token ” at each line that reads:

typedef <typename ListType>

I’m a student and I’ve been reading up on templates for a couple of hours but still cant figure this one out, any help would be much appreciated!

My hpp file for List:

#if !defined _LIST_HPP_
#define _LIST_HPP_

#include "Node.hpp"

///since we're creating a template everything must be defined in the hpp

typedef <typename ListType>
class List
{
   public:
      List();
      bool Empty();
      void PushFront();
      void PushBack();
      void PopBack();
      Node<ListType>& GetHead();

   private:
      int _size;
      Node<ListType>* _head;
      Node<ListType>* _tail;
};


///implement List class here
typedef <typename ListType>
List<ListType>::List() : _head(0), _tail(0), _size(0)
{
}
typedef <typename ListType>
bool <ListType>Empty()
{
   return !_size; //returns true if size = 0
}
typedef <typename ListType>
void List<ListType>::PushFront()
{
   _head = new Node<ListType>( _head , 0 );
   if (!Empty())
      _head->_prev->_next = _head; //set previous nodes _next to new _head

   ++_size;
}
typedef <typename ListType>
void List<ListType>::PushBack()
{
   _tail = new Node<ListType>( 0 , _tail);
   if (!Empty())
      _tail->_next->_prev = _tail; // set old tails _prev to new tail

   ++_size;
}
typedef <typename ListType>
void List<ListType>::PopBack()
{

}
typedef <typename ListType>
Node<ListType>& List<ListType>::GetHead()
{
   return _head;
}

#endif //define

And i’ll also include the templated node class hpp incase it could be something there that’s throwing things off?

#if !defined _NODE_HPP_
#define _NODE_HPP_


//#include "Sprite.hpp"

template<typename NodeType>
class Node{
   public:
      Node( Node* prev = 0, Node* next = 0);
      void SetData(NodeType newData);
      void GetData();
   private:
      friend class List;

      NodeType _data;
      Node* _next;
      Node* _prev;

};


///implement Node

template <typename NodeType>
Node<NodeType>::Node(Node* prev, Node* next) : _prev(prev), _next(next)
{}
template <typename NodeType>
void Node<NodeType>::SetData(NodeType newData)
{
   _data = newData;
}
template <typename NodeType>
void Node<NodeType>::GetData()
{
   return _data;
}

#endif //define
  • 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-05-31T19:33:53+00:00Added an answer on May 31, 2026 at 7:33 pm

    It’s template, not typedef.

    And while we’re at it, your preprocessor tokens are invalid identifiers since they start with an underscore, which isn’t allowed here. Use something like LIST_HPP instead.

    Finally, let’s take a look at your Empty definition:

    typedef <typename ListType>
    bool <ListType>Empty()
    {
       return !_size; //returns true if size = 0
    }
    

    First of all, this is missing the class name in the method name. Secondly, I dislike the conversion from a number to bool. Why not use an explicit comparison? That also obviates the comment, which is useless in itself since it merely paraphrases the code.

    This leaves us with:

    template <typename ListType>
    bool List<ListType>::Empty()
    {
        return _size != 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,

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.