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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:00:12+00:00 2026-06-04T17:00:12+00:00

I am a beginner both in programming and in C++. I have used templates

  • 0

I am a beginner both in programming and in C++. I have used templates before but in a very limited way and I have no idea what I am doing wrong:

template <typename TElement>
struct list{    // if I try list<TElement> => list is not a template
    TElement data;
    struct list *next;
} node_type;    // also tried node_type<TElement>, other incomprehensible errors
node_type *ptr[max], *root[max], *temp[max];

I find the error a bit incomprehensible: "node_type does not name a type"
What am I doing wrong ?

What I intend to do:
I want to have a list of type (so I can use this on several completely different Abstract Data Types – ADTs), so I’d like to end up with something like this:

Activities list *ptr[max], *root[max], *temp[max]

if that makes any sense (Where Activities is a class but can be any other class).

  • 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-04T17:00:14+00:00Added an answer on June 4, 2026 at 5:00 pm

    Don’t try to learn C++ by trial and error and guessing at the syntax, read a good book.

    template <typename TElement>
      struct list{
    

    This declares a struct template called list which has a single template parameter, TElement, which serves as an alias (only within the body of the template) for the type you instantiate the template with.

    If you instantiate list<int> then TElement will refer to int.
    If you instantiate list<char> then TElement will refer to char.
    etc.

    So the type you instantiate the template with will be substituted for TElement in your template definition.

    The error you got when trying:

    // if I try list<TElement> => list is not a template
    template <typename TElement>
      struct list<TElement> {
    

    is because this is not valid syntax, the error is telling you list isn’t a template because at the point where you write list<TElement> you haven’t finished declaring list yet, so the compiler has no idea what it is and you can’t have a list of something if the list template isn’t defined.

    template <typename TElement>
      struct list{
        TElement data;
        struct list *next;
      }node_type;
    

    This attempts to declares an object of type list, similar to this syntax:

    struct A {
      int i;
    } a;        // the variable 'a' is an object of type 'A'
    

    But in your case list is not a type, it’s a template. list<int> is a type, but list on its own is not a valid type, it’s just a template that a type can be made from when you “fill in the blanks” i.e. provide a type to substitute for the parameter TElement

    It looks like you weren’t even trying to declare a variable anyway, just blindly guessing at syntax.

    // also tried node_type<TElement>, other incomprehensible errors
    

    That won’t help either, node_type<TElement> is nonsense, if you want to declare a variable it needs a type, e.g. list<int>. The parameter TElement needs to be replaced with a type, it isn’t a type itself. Stop trying to string together random bits of syntax hoping it will work. You could start by reading http://www.parashift.com/c++-faq/templates.html

    On the last line:

    node_type *ptr[max], *root[max], *temp[max];
    

    node_type isn’t a type so that won’t work. Also, you should avoid getting into the bad habit of declaring multiple variables on a single line. It’s much clearer to write:

    int* p1;
    int* p2;
    

    Instead of

    int *p1, *p2;
    

    Also, are you sure youu want arrays of pointers? Since you clearly don’t know what you’re doing it would be more sensible to use standard container types that do the work for you.

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

Sidebar

Related Questions

I am a beginner programmer. I have a limited knowledge of javascript, but I
I am a beginner at both iPhone programming and SQL, yet I have basic
Absolute beginner question: I have a template file index.html that looks like this: ...
I'm learning C# now and a beginner in the programming world. I have a
I am a complete, total beginner in programming, although I do have knowledge of
I have written a program with both a Advanced Mode and a Beginner Mode
I'm a beginner but have been working really hard to build this application. Working
I'm a beginner at both NHibernate and Castle Windsor but the current application I'm
I am only a beginner to Android, but I have noticed a number of
I m beginner asp.net mvc developer.And I don't understand, Why has used both Json

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.