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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:28:56+00:00 2026-05-31T23:28:56+00:00

Okay, guys i have been trying to define a Stack , each node also

  • 0

Okay, guys i have been trying to define a Stack , each node also being of template type but i get dozen different types of errors when the prog tries to compile. i will paste the program which uses a char-type stack and tries to pop letter ‘e’

 #ifndef STACK_LIST_H
#define STACK_LIST_H
#include "List.h"

using namespace std;
template <class T>
class Stack {
public:
    T pop();
    void push(T x);
    T isEmpty();
    T top();

private:
    int      size;
    Node<T> *   headNode;
    Node<T> *   currentNode;


};

#endif

Now the function definitions:

    #include <iostream>
#include "Stack_list.h"

using namespace std;
template <class T>
T Stack<T>::pop(){
    T x = headNode->get();
    Node<T>* p = new Node<T>::Node();
    p = headNode;
    headNode = headNode->getNext();
    delete p;
    return x; }

template <class T>
void Stack<T>::push(T x){
    Node<T>* newNode = new Node<T>::Node();
    newNode->setNext(headNode);
    newNode->set(x);
    headNode=newNode;
}

template <class T>
int Stack<T>::isEmpty(){
return (headNode ==NULL);}

template <class T>
T Stack<T>::top(){
return headNode->get();
}

now the template class node:

#ifndef LIST_H
#define LIST_H

using namespace std;

/* The Node class */
template <class T>
class   Node
{
    public:
        Node(T here){object=here;};
        T get() { return   object; };
        void  set(T object) { this->object   =   object; };
        Node<T>* getNext() { return   nextNode; };
        void  setNext(Node<T>* nextNode) { this->nextNode   =   nextNode; };
        Node<T>* getPrev(){ return  prevNode;};
        void  setPrev(Node<T>* prevNode){this->prevNode=prevNode;};
    private:
       T object;
       Node<T>* nextNode;
       Node<T>* prevNode;
};
#endif

and finally the program that evokes the classes:

#include <iostream>
#include "Stack_list.cpp"
using namespace std;

int main(){
Stack <char>s;
s.push("e");
cout<<s.pop();
}

As you can see, this is my first try at template classes. In definitions of Stack::pop() and push(T) it says, “expected type-specifier before ‘Node’”

  • 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-31T23:28:57+00:00Added an answer on May 31, 2026 at 11:28 pm

    Node<T>* newNode = new Node() is inconsistent. Is Node a class or a class template? The first time that you mention it, you treat it as a template and instantiate it with T, but the second time you treat it as a class. It can’t be both.

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

Sidebar

Related Questions

Okay, here goes. Stack Overflow virgin here but hopefully you guys will be able
Okay guys I have a database I have been working on for days now.
Hye guys. Okay. I have done this coding. But it seems have error. Can
Okay guys, I have read through all the other posts and question on jQuery
Okay guys, basically the problem I'm having is this. I've been assigned to write
Okay guys, so I've been stuck for at least 2 days, with googling and
Okay, some Guys will know what i mean and edit my Question but they
Okay guys I have a question about positioning tables within DIV's using CSS. I
Okay, I have a question guys. I want to remote upload (copy an image
There have been similar questions but the answers weren't what I was looking for.

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.