I am building a stack class on top of my list class. I can't do it to save my life. Here is my list class, so can someone show me how to combine the two. And also, what is the point of doing so, if I can't access my list methods from the stack objects?
class stack
{
public:
// Typedefs and member constants
typedef size_t size_type;
typedefchar value_type;
staticconst size_type CAPACITY = 1000;
// Constructors
stack(); // Starts a new empty stack}
stack(stack& stackToCopy); // Copies a stack when declaring new stack
// Modification member functions
void push(const value_type& entry);
void pop();
// Constant member functions
value_type top() const; // Returns top value in array
size_type size() const; // Returns size of array
bool is_empty() const; // Checks to see if array is empty
private:
list myStack; // Partially filled array
};
From here, what do I do? How do I use both in a program?
You can consider interfaces of std::stack and std:: list.
I think you incorrectly defined for example member function of the list front. It shall return a reference to the first element of the list.
For example yoiu could declare it the following way
Thank you so much for responding! I will try that, thanks so much. Can you tell me why these function definitions are giving me a "reference to stack is ambiguous" error? What am I doing wrong? (I've since deleted all the code within them to start over, but still get the errors, so problem must be in the definitions themselves, I just don't understand what I did wrong. It's exactly how I've done them before...)
size is the only one that doesn't give that error. But it does say 'size_type' does not name a type. I don't understand that either, since I did a typedef for it...
So frustrated!!