Implementation/Header file question

I have an assignment to build a Stack class "on top of" a General List class I just made last week. Trouble is, the teacher tells us to do that as if I know what that means. We have been keeping all our code in the main program, so while I am aware that I can separate out the implementation/header files and include the directives at the top, I have never done it...
Is this what he means I'm supposed to do in order to build my stack "on top of the general list class?"
Can anyone give me some simple instructions on how I should go about this...I feel like this is a pretty *easy* assignment, if only I knew where to start.
(This stack program will only read in characters from a file and then spit them back out again in reverse to another file.)

Thank you very much to anyone who helps.

I'm not 100% sure what he implied by "stack" but from what I've done before and seen from others, he probably means a stack like a container.

It should be able to hold your other class, General List, increase in size, remove items when needed, and give you the size on demand.

Essentially you're going to be creating something similar to an array. I'm not sure if that helps much.
Yes, he does mean a container. And we are supposed to use an array. I just don't understand how to "build on top of" another program short of just adding new code to the original General List program. I know there is an easier way to do this, I am just not fully understanding it. Right now, I'm looking up how to take my General List definitions and put them into an implementation file so I can just use a statement at the top of the new program to access them....but that is proving to be a little harder (for me) than it sounds...
Do I need to create a namespace to do this, or can I just use an implementation file?
No, you're over thinking this a lot. The Stack class will contain the type General List.

Like I said, you can make the stack bigger, push an item off, add items. It's a fairly simple process.

A sample would be something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
class GeneralList {...}

class Stack {
public:
   Stack(); // Constructor
   ~Stack(); // Destructor
   int size(); // Return current size of stack
   void push_back(); // Add Item to end
   GeneralList pop(); // Remove and return last item
private:
   GeneralList myStack[20]; // Create Default size array
   int size; // Have a variable to hold the size of your stack
};


I'll leave the coding up to you on that.

Edit: And make sure that the Stack class comes after your generallist class.
Last edited on
Okay, so it's all in the same program? That's what I tried, initially...okay. Thanks. I have a question though. Why is push_back() not a GeneralList type, but pop() is?

~Is push_back() just a Stack function, then? I'm getting confused on combining these...and what exactly that means.

With my stack(); constructor, I keep getting a "Reference to stack is ambiguous" error. Do you know what that means?
Last edited on
push_back is the general name used for containers. Another name would be like add. I don't know what your general class looks like, I just threw one together. The Stack class is something you'd have to make altogether.
Last edited on
Topic archived. No new replies allowed.