This might be really simple or impossible, but what I need to do is somehow take what the user inputs in the client code, and set one of my variables in my constructor to the variable in the client code.
This is my client code
int main()
{
StackType<int> stack;
int num, item, valid =1, size;
while (valid != 0)
{
cout << endl << "How many integers will you input: ";
cin >> stack.StackType(size);
if (size <= MAX_SIZE)
{
valid = 0;
}
else
{
cout << endl << "Not a valid input, stack can only hold up to 10 integers" << endl;
valid = 1;
}
cout << endl;
}
This is my class coding
#ifndef STACK_H
#define STACK_H
using namespace std;
#include <iostream>
const int MAX_SIZE = 10;
class FullStack
{};
class EmptyStack
{};
template <class ItemType>
class StackType
{
public:
StackType(ItemType s);
~StackType();
StackType(const StackType<ItemType> &right);
void Clear();
bool IsFull() const;
bool IsEmpty() const;
void Push(ItemType item);
ItemType Pop();
ItemType Top();
void Print();
StackType<ItemType>& operator=(const StackType<ItemType> &right);
private:
ItemType *items;
int stackSize;
int top;
};
#endif
// Stack.cpp
template <class ItemType>
StackType<ItemType>::StackType(ItemType s)
{
top = -1;
stackSize = s;
items = new int[stackSize];
}
As you can see I need to set variable stackSize to what was input in the main program... any help or suggestions?