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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:18:02+00:00 2026-05-12T01:18:02+00:00

I compiled the following cords with g++ #include <iostream> #include <string> using namespace std;

  • 0

I compiled the following cords with g++

#include <iostream>
#include <string>
using namespace std;
template<class T>
class Node<const char*>{
private:
  string x_;
  Node* next_;
public:
  Node (const char* k, Node* next):next_(next),x_(k){}
  string data(){return x_;}
  Node *get_next(){return next_;}
};

$ g++ -c node01.cc
node01.cc:5: error: ‘Node’ is not a template

What’s wrong?
I’m begginer for c++

  • 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-12T01:18:02+00:00Added an answer on May 12, 2026 at 1:18 am

    You’re mixing up declarations and instantiations. When you declare a template, you don’t specify a type immediately after its name. Instead, declare it like this:

    template<class T>
    class Node {
    private:
      const T x_;
      Node *next_;
    public:
      Node (const T& k, Node *next) : x_(k), next_(next) { }
      const T& data(){return x_;}
      Node *get_next(){return next_;}
    };
    

    Your original declaration also confuses string, const char *, and generic types that should be in terms of T. For a template like this, you probably want to let the user define the type of the member (x_). If you explicitly declare it as const char * or string, you’re losing genericity by limiting what the user can use for T.

    Notice that I changed the types of the instance variables, the parameters of the constructor and the return type of data() to be in terms of T, too.

    When you actually instantiate a variable of the template type, you can provide a concrete type parameter, e.g.:

    int main(int argc, const char **argv) {
        Node<char*> *tail = new Node<char*>("tail", NULL);
        Node<char*> *node = new Node<char*>("node", tail);
        // do stuff to mynode and mytail
    }
    

    Whenever you write the template name Node outside the template declaration, it’s not complete until you provide a value for the parameter T. If you just say Node, the compiler won’t know what kind of node you wanted.

    The above is a little verbose, so you might also simplify it with a typedef when you actually use it:

    typedef Node<char*> StringNode;
    int main(int argc, const char **argv) {
        StringNode *tail = new StringNode("tail", NULL);
        StringNode *node = new StringNode("node", tail);
        // do stuff to mynode and mytail
    }
    

    Now you’ve built a linked list of two nodes. You can print out all the values in the list with something like this:

    for (StringNode *n = node; n; n = n->get_next()) {
        cout << n->data() << endl;
    }
    

    If all goes well, this will print out:

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

Sidebar

Ask A Question

Stats

  • Questions 163k
  • Answers 164k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you cannot use circular dependencies with unity at… May 12, 2026 at 12:17 pm
  • Editorial Team
    Editorial Team added an answer I would recommend a single web.config for each application and… May 12, 2026 at 12:17 pm
  • Editorial Team
    Editorial Team added an answer No. No. Many HTTP headers are optional. A typical browser… May 12, 2026 at 12:17 pm

Related Questions

problem I'm using LilyPond to typeset sheet music for a church choir to perform.
I compiled the following code as a shared library using g++ -shared ... :
I come into a strange problem in pthread programming I've compiled the following code
I've managed to get into a linux machine to try the HotKey library suggested

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.