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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:59:17+00:00 2026-06-10T15:59:17+00:00

I am trying to figure out exactly what I did wrong to gain the

  • 0

I am trying to figure out exactly what I did wrong to gain the below compiler error, I am using Bloodshed Dev-C++ 4.9.9.2:

Errors read:
prototype for ‘stackType::stackType(const stackType&)’ does not match any in class ‘stackType’ and template definition of non-template ‘stackType::stackType(const stackType&)’ for the one definition of my copy constructor

stackType<Type>::stackType(const stackType<Type>& otherStack) //definition of copy constructor
{
     list = NULL;
     copyStack(otherStack);
}

another error is stackType::stackType(int) but it doesn’t say anything further the code is for the definition of the constructor this error is:

template <class Type>
stackType<Type>::stackType(int stackSize) //definition of constructor
{
     if (stackSize <= 0)
     {
          cout << "Size of the array holding the stack must be positive." << endl;
          cout << "Creating an array of size 100." << endl;
          maxStackSize = 100;
     }
     else
          maxStackSize = stackSize; //sets stack size to value specified by parameter stackSize
          stackTop = 0; //sets stackTop to 0
          list = new Type[maxStackSize]; //creates array to hold elements of the stack
}

my final error that I am getting states In file included from C:\Users\Owner\Desktop\SD254\SD254 Unit7B.cpp and again does not say further. The above is obviously the directory for where the main file is stored on my computer but why is that an issue?? my full code is below.

header file:

#ifndef H_StackType
#define H_StackType
#include <iostream>
#include <cassert>


using namespace std;

template <class Type>
class stackADT
{
      public:
             virtual void initializeStack() = 0; //initialize stack
             virtual bool isEmptyStack() const = 0; //determines whether stack is empty or not
             virtual bool isFullStack() const = 0; //determines whether stack is full or not
             virtual void push(const Type& newItem) = 0; //adds new item to the stack
             virtual Type top() const = 0; //returns the top element to the stack
             virtual void pop() = 0; //removes the top element of the stack
};
template <class Type>
class stackType: public stackADT<Type>
{
      public:
             const stackType<Type>& operator=(const stackType<Type>&); //overloads assignment operator
             void initializeStack(); //initializes stack to empty state
             bool isEmptyStack() const; //determines stack is empty
             bool isFullStack() const; //determines stack is not full
             void push(const Type& newItem); //adds new item to stack
             Type top() const; //return the top element of the stack
             void pop(); //removes top element of the stack
             stackType(int stackSize = 100); //constructor and creates array with default size of 100
             ~stackType(); //destructor and removes all elements from the stack
             void copyStack(const stackType<Type>& otherStack); //copies other stack
      private:
              int maxStackSize; //stores maximum stack size
              int stackTop; //point to the top of the stack
              Type *list; //pointer to the array that holds the stack elements

};
template <class Type>
void stackType<Type>::initializeStack() //definition of function intializeStack
{
     stackTop = 0;
}
template <class Type>
bool stackType<Type>::isEmptyStack() const //definition of function isEmptyStack
{
     return(stackTop == 0);
}
template <class Type>
bool stackType<Type>::isFullStack() const //definition of function isFullStack
{
      return (stackTop == maxStackSize);
}
template <class Type>
void stackType<Type>::push(const Type& newItem) //definition of push function
{
     if (!isFullStack())
     {
          list[stackTop] = newItem; //adds new item to top of stack
          stackTop++; //increments stackTop
     }
     else
          cout << "Cannot add to a full stack." << endl;
}
template <class Type>
Type stackType<Type>::top() const //definition of top-returns the top element to the stack
{
     assert(stackTop != 0); //if stack is empty terminate program
     return list[stackTop - 1]; //return element of the stack indicated by stackTop -1
}
template <class Type>
void stackType<Type>::pop() //definition of function pop
{
     if (!isEmptyStack())
          stackTop--; //decrement stackTop
     else
          cout << "Cannot remove from an empty stack." << endl;
}
template <class Type>
void stackType<Type>::copyStack(const stackType<Type>& otherStack) //definition to make copy of stack
{
     delete [] list;
     maxStackSize = otherStack.maxStackSize;
     stackTop = otherStack.stackTop;
     list = new Type[maxStackSize]; //copies otherStack into this one
     for (int j = 0; j < stackTop; j++)
          list[j] = otherStack.list[j];
}
template <class Type>
stackType<Type>::stackType(int stackSize) //definition of constructor
{
     if (stackSize <= 0)
     {
          cout << "Size of the array holding the stack must be positive." << endl;
          cout << "Creating an array of size 100." << endl;
          maxStackSize = 100;
     }
     else
          maxStackSize = stackSize; //sets stack size to value specified by parameter stackSize
          stackTop = 0; //sets stackTop to 0
          list = new Type[maxStackSize]; //creates array to hold elements of the stack
 }
template <class Type>
stackType<Type>::~stackType() //definition of destructor
{
     delete [] list; //deallocates the memory occupied by the array
}
template <class Type>
stackType<Type>::stackType(const stackType<Type>& otherStack) //definition of copy constructor
{
     list = NULL;
     copyStack(otherStack);
}
template <class Type>
const stackType<Type>& stackType<Type>::operator=(const stackType<Type>& otherStack) //overload assignment operator
{
      if (this != &otherStack) 
           copyStack(otherStack);
      return *this;
}
#endif

the actual program file is:

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

using namespace std;
void testCopyConstructor(stackType<int> otherStack);
int main()
{
    stackType<int> stack(25);
    stackType<int> copyStack(25);
    stackType<int> dummyStack(50);

    stack.initializeStack();
    stack.push(15);
    stack.push(10);
    stack.push(20);
    copyStack = stack; //copies stack into copyStack

    cout << "The elements of copyStack: " ;
    while (!copyStack.isEmptyStack()) //prints copyStack
    {
          cout << copyStack.top() << " ";
          copyStack.pop();
    }
    cout << endl;
    copyStack = stack;
    testCopyConstructor(stack); //tests the copy constructor
    if (!stack.isEmptyStack())
         cout << "The original stack is not empty." << endl; 
         cout << "The top element of the original stack: " << copyStack.top() << endl;
    dummyStack = stack; //copies stack into dummyStack
    cout << "The elements of dummyStack: ";
    while (!dummyStack.isEmptyStack()) //prints dummyStack
    {
          cout << dummyStack.top() << " " ;
          dummyStack.pop();
    }
    cout << endl;
    return 0;
 }
void testCopyConstructor(stackType<int> otherStack)
{
     if (!otherStack.isEmptyStack())
         cout << "otherStack is not empty." << endl; 
         cout << "The top element of otherStack: " << otherStack.top() << endl;
}

Can anyone help me figure out how to fix the errors so I can get it to compile and build correctly, thanks in advance for any help I receive.

  • 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-10T15:59:18+00:00Added an answer on June 10, 2026 at 3:59 pm

    You have to add a declaration for the copy constructor in the class definition; you can’t just define it out of the blue.

    The class definition should look like

    template<typename Type>
    class stackType: public stackADT<Type>
    {
    public:
        stackType(const stackType&);
        // ... all the other stuff
    };
    

    Then the function definition below will be recognised.

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

Sidebar

Related Questions

I am trying to figure out exactly what these new fangled data stores such
I am trying to figure out exactly how to implement a callback function which
I'm trying to figure out what exactly Dependency Properties are, but when I look
I've been trying to figure out what exactly is happening here. I'm just trying
Just out of curiosity, I'm trying to figure out which exactly is the right
I am trying to figure out how exactly does treesort from here work (I
I'm trying to figure out how to implement the Share button exactly as how
I'm trying to figure out exactly how I should work around this. When I
I'm trying to figure out exactly what happens when you link to a same-domain
I am trying to figure out exactly why this script wont work. I first

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.