stack.h:36: error: âint Stack<int>::topâ is private
Pro1.h:59: error: within this context
Pro1.h:60: error: statement cannot resolve address of overloaded function
stack.h:36: error: âint Stack<int>::topâ is private
Pro1.h:61: error: within this context
Pro1.h:62: error: statement cannot resolve address of overloaded function
Pro1.h:72: warning: converting to âintâ from âdoubleâ
stack.h:36: error: âint Stack<int>::topâ is private
Pro1.h:90: error: within this context
stack.h: In function âvoid Convert(const std::string&, std::string&)â:
stack.h:36: error: âint Stack<char>::topâ is private
Pro1.h:206: error: within this context
Pro1.h:206: error: âOperatorStack.Stack<char>::topâ cannot be used as a function
stack.h:36: error: âint Stack<char>::topâ is private
Pro1.h:208: error: within this context
Pro1.h:208: error: âOperatorStack.Stack<char>::topâ cannot be used as a function
Pro1.h:209: error: no matching function for call to âStack<char>::pop()â
stack.h:26: note: candidates are: bool Stack<DataType>::pop(DataType&) [with DataType = char]
Pro1.h:212: error: âclass Stack<char>â has no member named âemptyâ
Pro1.h:213: error: no matching function for call to âStack<char>::pop()â
stack.h:26: note: candidates are: bool Stack<DataType>::pop(DataType&) [with DataType = char]
Pro1.h:219: error: âclass Stack<char>â has no member named âisEemptyâ
stack.h:36: error: âint Stack<char>::topâ is private
Pro1.h:221: error: within this context
Pro1.h:221: error: âOperatorStack.Stack<char>::topâ cannot be used as a function
Pro1.h:222: error: no matching function for call to âStack<char>::pop()â
stack.h:26: note: candidates are: bool Stack<DataType>::pop(DataType&) [with DataType = char]
Could you please paste the code in one block and between code tags (which you can find on right hand side of the box, it says Format and sign is #) ? It's so hard to read what you have pasted.
// removes an element from the top of the stack and returns it in poppedElement;
// returns false if called on an empty stack; otherwise, returns true
bool pop( DataType & poppedElement );
// returns the element at the top of the stack in topElement without removing it
// returns false is called on an empty stack; otherwise, returns true
bool peek( DataType & topElement );
bool isEmpty( ) const; // returns true if the stack is empty;
// otherwise, returns false
void makeEmpty( );
private:
Array<DataType> elements;
int top;
-----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
THIS IS STACK.CPP
#ifndef INC_STACK_H
#define INC_STACK_H
#endif
#if _MSC_VER > 1000
#pragma once
#endif
#include <string>
#include "array.cpp"
using namespace std;
// removes an element from the top of the stack and returns it in poppedElement;
// returns false if called on an empty stack; otherwise, returns true
bool pop( DataType & poppedElement );
// returns the element at the top of the stack in topElement without removing it
// returns false is called on an empty stack; otherwise, returns true
bool peek( DataType & topElement );
bool isEmpty( ) const; // returns true if the stack is empty;
// otherwise, returns false
void makeEmpty( );
private:
Array<DataType> elements;
int top;
};
~
[santa_gm@pegasus dEt]$ vi stack.cpp
// stack.cpp -- the function definitions for the array implementation of a stack
// removes an element from the top of the stack and returns it in poppedElement;
// returns false if called on an empty stack; otherwise, returns true
template <class DataType>
bool Stack<DataType>::pop( DataType & poppedElement )
{
if ( top == -1 )
return false;
poppedElement = elements[ top ];
top--;
int trysize = elements.length( );
while ( ( top + 1 <= trysize >> 2 ) && trysize > 2 )
trysize >>= 1;
// returns the element at the top of the stack in topElement without removing it
// returns false if called on an empty stack; otherwise, returns true
template <class DataType>
bool Stack<DataType>::peek( DataType & topElement )
{
if ( top == -1 )
return false;
topElement = elements[ top ];
return true;
}
-----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------- THIS IS P1.H
-----------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
This is P1.CPP
As far as I know, when you use template classes, the implementation of the template class **MUST** be in the same file, the .h file itself, not the case with the code you posted above!
I use template classes quite a lot in my small project, and all implementation of the template classes is located in my .h file.