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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:17:58+00:00 2026-06-13T14:17:58+00:00

So I wrote a Linked List based implementation of the Stack ADT recently. However,

  • 0

So I wrote a Linked List based implementation of the Stack ADT recently. However, I’m not quite sure why there is a bit of a discrepancy between how the nodes of the Stack are being declared. The compiler gets very angry and won’t compile until I write them a certain way for certain functions. I’m extremely curious as to why this is the case.

Here are two different methods which the compiler wants two different formats.

Here is my destructor where the compiler wants StackNode *temp.

template <typename DataType>
StackLinked<DataType>::~StackLinked() {
   StackNode *temp;
   while (top != 0) {
       temp = top;
       top = top->next;
       delete temp;
   }
}

Here is my assignment operator overload where the compiler wants StackNode<DataType> *temp.

template <typename DataType>
StackLinked<DataType>& StackLinked<DataType>::operator=(const StackLinked& other) {
    if (this != &other) {
        StackNode<DataType> *newNode, *current, *last;

        if (top != 0) {
           StackNode<DataType> *temp;
           while (top != 0) {
               temp = top;
               top -> top->next;
               delete temp;
           }
        }

        if (other.top == 0) {
            top = 0;
        }
        else {
            current = other.top;
            top = new StackNode<DataType>;
            top->dataItem = current->dataItem;
            top->next = 0;
            last = top;
            current = current->next;

            while (current != 0) {
                newNode = new StackNode<DataType>;
                newNode->dataItem = current->dataItem;
                newNode->next = 0;
                last-> next = newNode;
                last = newNode;
                current = current->next;
            }
        }
    }
    return *this;
}

I don’t know why this is, but the unknown is bothering me.

Note: My StackNode class is an inner class of the StackLinked class.

EDIT: Class declaration:

#ifndef STACKARRAY_H
#define STACKARRAY_H

#include <stdexcept>
#include <iostream>

using namespace std;

#include "Stack.h"

template <typename DataType>
class StackLinked : public Stack<DataType> {

public:

StackLinked(int maxNumber = Stack<DataType>::MAX_STACK_SIZE);
StackLinked(const StackLinked& other);
StackLinked& operator=(const StackLinked& other);
~StackLinked();

void push(const DataType& newDataItem) throw (logic_error);
DataType pop() throw (logic_error);

void clear();

bool isEmpty() const;
bool isFull() const;

void showStructure() const;

private:
class StackNode {
  public:
StackNode(const DataType& nodeData, StackNode* nextPtr);
DataType dataItem;
StackNode* next;
};

StackNode* top;
};

#endif  

If any other details are needed. Just ask! Thank you for your time!

  • 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-13T14:17:59+00:00Added an answer on June 13, 2026 at 2:17 pm

    From the code you showed, StackNode<DataType> is not correct, because StackNode is not a class template.

    This makes me think you have a template also named StackNode that the compiler is finding. Go check whether any of your files contain another version of StackNode.

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

Sidebar

Related Questions

I wrote a Stack and Queue implementation (Linked List based). There is one stack
I wrote a linked list implementation for my java class earlier this year. This
I just wrote a simple linked list, however when iterating through the list via
Below, I wrote a primitive singly linked list in C. Function addEditNode MUST receive
I have read other related posts, but am still not quite sure how, or
I wrote a method which creates a copy of linked list. Can you guys
For a project I'm working on, I'm implementing a linked-list data-structure, which is based
For a project I'm working on, I'm implementing a linked-list data-structure, which is based
I quickly wrote a linked list class in Java. I want to write another
i have wrote code for quicksort with linked list ,here is code #include<stdio.h> #include<iostream>

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.