Young cheol Ko
Young cheol Ko

Reputation: 3

How to fix "use of class template requires template argument list"

i made some code about stack using template. but right now, stuck with the little error. i tried many times as i can but don't know what to do. also, i see the a lot of same error question but my one is seems to be different.

I'm middle of the writing. so, there is some uncompleted code. if you see something wrong but not cause the error, ignore it please.

#ifndef STACKINTERFACE_H
#define STACKINTERFACE_H

using namespace std;

template <typename T>
class StackInterface {
public:
    StackInterface() {};
    virtual ~StackInterface() {};
    virtual bool isEmpty() const = 0;
    virtual bool isFull() const = 0;
    virtual void push(T data) = 0;
    virtual void pop() = 0;
    virtual T top() const = 0;
};


#include "StackInterface.h"

#include <iostream>
template <typename T>
class Stack : public StackInterface {
private:
    T * items;
    const static int max = 10;
    const static int GROWBY = 5;
    size_t arrayCapacity;
    size_t numItems;
    int top_position;
public:
    Stack();
    virtual void push(T data);
    virtual T top() const;
    virtual void pop();
    virtual bool isEmpty() const;
    virtual bool isFull() const;
    size_t getArrayCapacity();
    size_t getNumItems();
    Stack<T> operator=(const Stack<T>&Other);
    ~Stack();
    Stack(const Stack<T>& other);
};

template <typename T>
Stack<T>::Stack() 
{
    items = new T[max];
    numItems = 0;
    top_position = -1;
}

template <typename T>
Stack<T>::~Stack() {
    cout << "deleting..." << endl;
    delete[] items;
}

template <typename T>
void Stack<T>::push(T data) {
    cout << "inserting" << data << endl;
    if (numItems < arrayCapacity) {
        T[++top_position] = data;
    }
    numItems++;
}
template <typename T>
void Stack<T>::pop() {
    if (isEmpty) {
        cout << "The stack is empty. Returned value not reliable.\n";
    }
    else {
        cout << "removing" << top() << endl;
        retrun T[top_position--];
    }
}

template <typename T>
bool Stack<T>::isEmpty() const
{
    if (numItems == 0) {
        return true;
    }
    else {
        return false;
    }
}

template <typename T>
bool Stack<T>::isFull() const
{
    if (numItems == max) {
        return true;
    }
    else {
        return false;
    }
}

template <typename T>
T Stack<T>::top() const
{
    if (!isEmpty()) {
        return T[top_position];
    }
    else {
        throw exception;
    }
}

template <typename T>
Stack <T> Stack<T>:: operator=(const Stack<T>&Other) {
    if (&Other == this) {
        return *this;
    }   
}

template <typename T>
Stack<T>::Stack(const Stack<T>& other) {
    items = new items(other.items);
    numItems = other.numItems;
    top_position = other.top_position;
    arrayCapacity = other.arrayCapacity;
}

template <typename T>
size_t Stack<T>::getArrayCapacity() {
    return arrayCapacity;
}

template <typename T>
size_t Stack<T>::getNumItems() {
    return numItems;
}

int main() {

    Stack <int> S1;


    system("pause");
    return 0;
}

Upvotes: 0

Views: 455

Answers (1)

You need to give template arguments to your superclass. Instead of this:

template <typename T>
class Stack : public StackInterface {

Do this:

template <typename T>
class Stack : public StackInterface<T> {

(There's lots of other problems with your code too, but that's how you fix the specific one you asked about.)

Upvotes: 3

Related Questions