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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:32:52+00:00 2026-05-23T02:32:52+00:00

In .NET I really liked System.Generic.List and wanted to replicate it as a way

  • 0

In .NET I really liked System.Generic.List and wanted to replicate it as a way of learning the C++ language. The problem is that I want it to be generic, I want the elements to contain a value of a template type T. I know most of what to do, but the problem lies within the node.

template<class T>
struct node
{
    T value;
    bool isFirst;
    node *next;
};

I have tried googling this for a while and haven’t found anything relevant. I have just gone through the tutorials at http://www.cplusplus.com. Do I have to reference the class here with a pointer, if so, how?

Thanks in advance

Gisle Aune

  • 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-23T02:32:53+00:00Added an answer on May 23, 2026 at 2:32 am

    There’s nothing wrong with your code. Actually, I would probably write it as

    template<class T>
    struct node
    {
        T value;
        bool isFirst;
        node<T> *next;
    };
    

    because it’s not much more verbose and it’s clearer that next points to a node of the same type, but nevertheless also your version is fine: in a template, when you use the name of the class without explicitly specifying the template parameters, it’s implied that they are the same ones of the template being currently instantiated. This is explained at §14.6.1 of the C++ standard:

    Within the scope of a class template, when the name of the template is neither qualified nor followed by <, it is equivalent to the name of the template followed by the template-parameters enclosed in <>. [Example: the constructor for Set can be referred to as Set() or Set<T>(). ] Other specializations (14.7.3) of
    the class can be referred to by explicitly qualifying the template name with the appropriate template-arguments. [Example:

    template<class T> class X {
        X* p;      // meaning X<T>
        X<T>* p2;
        X<int>* p3;
    };
    

    —end example]


    By the way, writing a generic list is a useful exercise to learn the language, but keep in mind that many generic containers are already available in the C++ standard library; besides the fact that they are throughly tested and optimized, their “iterators” abstraction allow you to use on almost any container the freestanding algorithms available in the library.

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

Sidebar

Related Questions

I really like the MVC way and have actually enjoyed learning ASP.NET MVC (I
I really want to know your experience at working with ADO.Net datasets (calling stored
okay...im really puzzled with this. I want to create a regular asp.net webforms website
I have an ASP.NET MVC web app which has a really basic subscription system
Why does System.Xml.XmlDocument.LoadXml method throw System.Net.WebException ? This is really mind boggling crazy, if
First of all, I'm really new to the MVC Asp.Net ideology. I would like
I'm really new to ASP.NET MVC, and I'm trying to integrate some Javascript into
I am really curious to know how the Expando Object in .Net 4.0 has
My .NET application (VB.NET 3.5 if you really must know) forms do not properly
I've never really done any charting or graphing in asp.net, but my current project

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.