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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:38:01+00:00 2026-05-20T10:38:01+00:00

I have a node struct and stack class. When I put the definition for

  • 0

I have a node struct and stack class. When I put the definition for ‘void Push(T data)’ outside the class definition I get:

error: 'template<class T> class Stack' used without template parameters

But when I put it inside the class definition it works fine.
Here is the code:

template <class T>
struct Node
{
    Node(T data, Node <T> * address) : Data(data), p_Next(address) {}
    T Data;
    Node <T> * p_Next;
};

template <class T> 
class Stack
{
public:

    Stack() : size(0) {}
    void Push(T data);
    T Pop();

private:
    int size;
    Node <T> * p_first;
    Node <T> * p_last;  
};

The implementation for Push(T data) is :

void Stack::Push(T data)
{
    Node <T> * newNode;   

    if(size==0)
        newNode = new Node <T> (data, NULL);
    else
        newNode = new Node <T> (data, p_last);

    size++;
    p_last = newNode;
}

Edit: The solutions worked except that now I get a linking error whenever I try to call the functions.

Stack<int>::Pop", referenced from   
_main in main.o   
symbol(s) not found.

unless the definitions are in Stack.h instead of Stack.cpp

  • 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-20T10:38:02+00:00Added an answer on May 20, 2026 at 10:38 am

    You need to use the template <class T> again (and then use that T again as the template parameter for the class):

    template <class T>
    void Stack<T>::Push(T data)
    {
        Node <T> * newNode;   
    
        if(size==0)
            newNode = new Node <T> (data, NULL);
        else
            newNode = new Node <T> (data, p_last);
    
        size++;
        p_last = newNode;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include<stdio.h> #include<conio.h> #include<alloc.h> struct node { int data; struct node*link; }; void push(struct node*,int);
I have a generic linked list implementation with a node struct containing a void*
I have a base class Node which contains a list of child nodes. Node
I have a tree data structure that is L levels deep each node has
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
So i have struct node { int number; struct node *next; struct deck{ int
I have the following C-code: #include<stdio.h> #include<stdlib.h> typedef struct node { int a; }node;
I am implementing a queue in C. I have a struct like: struct Node
I have a class like this: template <class T> class bag { private: typedef
I have a class something like that: template <class T> class bag { public:

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.