Im getting linker errors when trying to create a class template. I can't seem to see what is bad with this code. Any help would be great, thanks.
in main.cpp:
Code:
// main.cpp : practice.
#include <iostream>
using namespace std;
#include "Stack.h"
/***********/
/* Globals */
/***********/
/**************/
/* Prototypes */
/**************/
/************/
/* Internal */
/************/
// Our primary routine. This is called when the program starts.
//
// Return: We always return 0.
int main(void)
{
CStack<int> values;
int num = 4;
if (values.isEmpty())
cout << "Values is empty..\n";
else
cout << "Values has an item in it..\n";
num = 5;
cout << "Adding 5 to CStack values...\n";
values.push_back(num);
num = 3;
cout << "Adding 3 to CStack values...\n";
values.push_back(num);
cout << "Taking one out.\n";
values.pop(num);
cout << num << "Removed..\n";
}
in Stack.h
Code:
#pragma once
template <typename Type>
class CStack
{
private:
static const int MAX = 10;
Type items[MAX];
int top;
public:
CStack(void);
bool isFull(void) const;
bool isEmpty(void) const;
bool push_back(const Type & item);
bool pop(Type & item);
};
in Stack.cpp
Code:
#include "Stack.h"
template <typename Type>
CStack<Type>::CStack(void)
{
top = 0;
}
template <typename Type>
bool CStack<Type>::isFull(void) const
{
return top == MAX;
}
template <typename Type>
bool CStack<Type>::isEmpty(void) const
{
return top == 0;
}
template <typename Type>
bool CStack<Type>::push_back(const Type & item)
{
if (top < max)
{
items[top++] = item;
return true;
}
else
return false;
}
template <typename Type>
bool CStack<Type>::pop(Type & item)
{
if (top > 0)
{
item = items[--top];
return true;
}
else
return false;
}