I am getting an error in the header file:
class linkedStackType: public stackADT<Type>
Can you see anything wrong with what I have, and why the compiler is complaining about "stackADT"? I would love it if you could give me some insight into this matter. Right now I'm only concerned about getting it to compile. I can troubleshoot logic errors (if any exist) after I get it running.
Thanks in advance,
Dani
#include "linkedStackType.h"
//initialize the stack
template <class Type>
void linkedStackType<Type>::initializeStack(){
nodeType<Type> *temp;
while(stackTop != NULL){
temp = stackTop;
stackTop = stackTop->link;
delete temp;
}
}
//check if stack is full
template <class Type>
bool linkedStackType<Type>::isFullStack() const{
return false;
}
//check if stack is empty
template <class Type>
bool linkedStackType<Type>::isEmptyStack() const{
return (stackTop == NULL);
}
//add layers to the stack
template <class Type>
void linkedStackType<Type>::push(const Type& newItem){
nodeType<Type> *newNode;
newNode = new nodeType<Type>;
newNode->info = newItem;
newNode->link = stackTop;
stackTop = newNode;
}
//remove a layer from the stack
template <class Type>
void linkedStackType<Type>::pop(){
nodeType<Type> *temp;
if(stackTop != NULL){
temp = stackTop;
stackTop = stackTop->link;
delete temp;
}
else
cout << "Stack is empty." << endl;
}
//top of stack
template <class Type>
Type linkedStackType<Type>::top() const{
assert(stackTop != NULL);
return stackTop->info;
}
//overload operator =
template <class Type>
const linkedStackType<Type>&linkedStackType<Type>::operator =(const linkedStackType<Type> &otherStack){
if(this != &otherStack)
copyStack(otherStack);
return *this;
}
//overload operator ==
template <class Type>
bool linkedStackType<Type>::operator ==(const linkedStackType<Type> &otherStack){
if((this->stackTop == NULL) & (otherStack.stackTop == NULL))
return true;
nodeType<Type> *temp1, *temp2;
temp1 = this->stackTop;
temp2 = otherStack.stackTop;
while((temp1 != NULL) && (temp2 != NULL)){
if(temp1->info != temp2->info){
return false;
}
else{
temp1 = temp1->link;
temp2 = temp2->link;
}
}
if((temp1 != NULL) || (temp2 != NULL))
return false;
return true;
}
//copy contents of one stack to another
template <class Type>
void linkedStackType<Type>::copyStack(const linkedStackType<Type>& otherStack){
nodeType<Type> *newNode, *current, *last;
if(stackTop != NULL)
initializeStack();
if(otherStack.stackTop == NULL)
stackTop = NULL;
else{
current = otherStack.stackTop;
stackTop = new nodeType<Type>;
stackTop->link = NULL;
last = stackTop;
current = current->link;
while(current != NULL){
newNode = new nodeType<Type>;
newNode->info = current->info;
newNode->link = NULL;
last->link = newNode;
last = newNode;
current = current->link;
}
}
}
//constructor
template <class Type>
linkedStackType<Type>::linkedStackType(){
stackTop = NULL;
}
//copy constructor
template <class Type>
linkedStackType<Type>::linkedStackType(const linkedStackType<Type>& otherStack){
stackTop = NULL;
copyStack(otherStack);
}
//destructor
template <class Type>
linkedStackType<Type>::~linkedStackType(){
initializeStack();
}
/*
* File: linkedStackType.h
Dani
* Created on April 13, 2014, 3:29 PM
*/
#ifndef LINKEDSTACKTYPE_H
#define LINKEDSTACKTYPE_H
#include <iostream>
#include <cassert>
using namespace std;
//define the node
template <class Type>
struct nodeType{
Type info;
nodeType<Type> *link;
};
//template definition
template <class Type>
class linkedStackType: public stackADT<Type>{
public:
//overload operator =
const linkedStackType<Type>& operator=(const linkedStackType<Type> &);
//overload operator ==
bool operator==(const linkedStackType<Type> &);
//initialize the stack
void initializeStack();
//is stack full
bool isFullStack() const;
//is stack empty
bool isEmptyStack() const;
//add another layer to the stack
void push(const Type& newItem);
//remove top layer of the stack
void pop();
//return top layer of stack
Type top() const;
// constructor
linkedStackType();
//copy constructor
linkedStackType(const linkedStackType<Type>& otherStack);
//destructor
~linkedStackType();
private:
//pointer to the stack
nodeType<Type> *stackTop;
//function to make copy of otherStack
void copyStack(const linkedStackType<Type>& otherStack);
};
#endif
/*
* File: main.cpp
Dani
*/
#include <cstdlib>
#include <iostream>
#include "linkedStackType.h"
using namespace std;
void testCopy(linkedStackType<int> OStack);
int main(){
cout << "This program overloads the equality operator to compare two stacks." << endl << endl;
//create two stacks
linkedStackType<int> s1;
linkedStackType<int> s2;
cout << "Loading both stacks with increments of 3." << endl << endl;
//load the stacks
for(int i = 3; i < 66; i += 3)
s1.push(i);
s2 = s1;
//check for equality
if(s1 == s2)
cout << "The stacks are equal." << endl << endl;
else
cout << "The stacks are not equal." << endl << endl;
cout << "Inserting a different element into the first stack..." << endl << endl;
//insert another value into s1 (creating inequality in the two stacks)
s1.push(78);
//check for equality
if(s1 == s2)
cout << "The stacks are equal." << endl << endl;
else
cout << "The stacks are not equal." << endl << endl;
//display elements in both stacks
cout << "Elements in the first stack: ";
while(!s1.isEmptyStack()){
cout << s1.top() << " ";
s1.pop();
}
cout << endl;
cout << "Elements in the second stack: ";
while(!s2.isEmptyStack()){
cout << s2.top() << " ";
s2.pop();
}
return 0;
}
COMPILED ERRORS:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Kevin/Documents/NetBeansProjects/CS270_Ch7_Ex2'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/cs270_ch7_ex2.exe
make[2]: Entering directory `/cygdrive/c/Users/Kevin/Documents/NetBeansProjects/CS270_Ch7_Ex2'
mkdir -p build/Debug/Cygwin-Windows
rm -f build/Debug/Cygwin-Windows/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/Cygwin-Windows/main.o.d -o build/Debug/Cygwin-Windows/main.o main.cpp
nbproject/Makefile-Debug.mk:67: recipe for target `build/Debug/Cygwin-Windows/main.o' failed
make[2]: Leaving directory `/cygdrive/c/Users/Kevin/Documents/NetBeansProjects/CS270_Ch7_Ex2'
nbproject/Makefile-Debug.mk:60: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/Kevin/Documents/NetBeansProjects/CS270_Ch7_Ex2'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed
In file included from main.cpp:11:
linkedStackType.h:26: error: expected template-name before '<' token
linkedStackType.h:26: error: expected `{' before '<' token
linkedStackType.h:26: error: expected unqualified-id before '<' token
linkedStackType.h:26: error: expected `;' before '<' token
main.cpp: In function `int main()':
main.cpp:22: error: aggregate `linkedStackType<int> s1' has incomplete type and cannot be defined
main.cpp:23: error: aggregate `linkedStackType<int> s2' has incomplete type and cannot be defined
make[2]: *** [build/Debug/Cygwin-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)