Hello,

I need help i am trying to compile some code using G++ compiler and i am receiving the following errors (see below). What am i doing wrong here, how can i get this to compile?


Header:
Code:
/* 
 * File:   stack.h
 * Author: 
 *
 * Created on April 5, 2008, 7:36 PM
 */
#include <dos.h>        // For sleep()
#include <iostream>   // For I/O
#include <windows.h>    // For MessageBox API
#include <conio.h>

#ifndef _STACK_H
#define	_STACK_H
#define MAX 10 // Maximum stack Content

template <class T>  // Using Templates so that any type of data can be
                    // stored in Stack without multiple defination of class

class Stack {
public:    
    Stack();
    void Push(T a);
    T Pop();
    virtual ~Stack();
    T item,r;
    int top;        //Contains location of Topmost Data pushed onto Stack
private:

protected:
    T arr[MAX];     // Contains all the Data

};

#endif	/* _STACK_H */

C++ Class
Code:
/* 
 * File:   stack.cpp
 * Author: 
 * 
 * Created on April 5, 2008, 7:36 PM
 */

#include "stack.h"

Stack::Stack() {

    for (int i = 0; i < MAX; i++) {
        arr[i] = NULL; //Initialises all Stack Contents to NULL
    }

    top = -1; //Sets the Top Location to -1 indicating an empty stack
}

Stack::~Stack(){
    
}

Stack::Push(T a) {

    top++; // increment to by 1
    if (top < MAX) {
        arr[top] = a; //If Stack is Vacant store Value in Array
    } else // Bug the User
    {
        MessageBox(0, "STACK IS FULL", "STACK WARNING!", MB_ICONSTOP);
        top--;
    }
}

Stack::Pop() {

    if (top == -1) {
        MessageBox(0, "STACK IS EMPTY","WARNING",MB_ICONSTOP);
        return NULL;
    } else {
        T data = arr[top];  //Set Topmost Value in data
        arr[top] = NULL; //Set Original Location to NULL
        top--;      // Decrement top by 1
        return data;        // Return deleted item
    }
}


Errors:
Running "C:\MSYS\1.0\bin\make.exe -f Makefile CONF=Debug" in C:\Users\Willie Johnson Jr\Documents\NetBeansProjects\Stack_Templates

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/Willie Johnson Jr/Documents/NetBeansProjects/Stack_Templates'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/stack_templates.exe
make[2]: Entering directory `/c/Users/Willie Johnson Jr/Documents/NetBeansProjects/Stack_Templates'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/stack.o.d
g++.exe -c -g -MMD -MP -MF build/Debug/MinGW-Windows/stack.o.d -o build/Debug/MinGW-Windows/stack.o stack.cpp
stack.h: In instantiation of `Stack<void>':

stack.cpp:10: instantiated from here

stack.h:22: error: invalid parameter type `void'

stack.h:22: error: in declaration `void Stack<T>::Push(T)'

stack.h:25: error: instantiation of `Stack<T>::item' as type `void'

stack.h:25: error: `Stack<T>::item' has incomplete type

stack.h:25: error: invalid use of `void'

stack.h:25: error: instantiation of `Stack<T>::r' as type `void'

stack.h:25: error: `Stack<T>::r' has incomplete type

stack.h:25: error: invalid use of `void'

stack.h:30: error: creating array of `void'

stack.cpp:10: error: return type specification for constructor invalid

stack.cpp: In constructor `Stack<T>::Stack() [with T = void]':

stack.cpp:13: error: `arr' was not declared in this scope

stack.cpp: At global scope:

stack.cpp:19: error: expected constructor, destructor, or type conversion before '::' token

stack.cpp:23: error: `template<class T> class Stack' used without template parameters

stack.cpp:23: error: expected constructor, destructor, or type conversion before '(' token

stack.cpp:35: error: `template<class T> class Stack' used without template parameters

stack.cpp:35: error: ISO C++ forbids declaration of `Pop' with no type

stack.cpp: In function `int Pop()':

stack.cpp:37: error: `top' was not declared in this scope

stack.cpp:39: warning: converting to non-pointer type `int' from NULL

stack.cpp:41: error: `T' was not declared in this scope

stack.cpp:41: error: expected `;' before "data"

stack.cpp:42: error: `arr' was not declared in this scope

stack.cpp:44: error: `data' was not declared in this scope

make[2]: *** [build/Debug/MinGW-Windows/stack.o] Error 1
make[2]: Leaving directory `/c/Users/Willie Johnson Jr/Documents/NetBeansProjects/Stack_Templates'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/Users/Willie Johnson Jr/Documents/NetBeansProjects/Stack_Templates'
make: *** [.build-impl] Error 2

Build failed. Exit value 2.