#Compiler giving the error?

24 messages · Page 1 of 1 (latest)

hallow geodeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

warm sinew
#

@lime valve More info needed

#

this is probably a syntax error though

lime valve
#

Yes i know but main error is
OperatorStack(length)

#

I don't know how to remove this

warm sinew
#

We can only help if you send the error message

lime valve
warm sinew
#

Please send the error as text

#

not the worst photo known to man 😉

#

It's also better to look at the actual errors from the compiler, not what vscode shows

lime valve
#

MyStack<char> operatorStack(length);
This line giving the error

warm sinew
#

Show the definition of MyStack

lime valve
#
#include "Stack.h"

template<class T>
class MyStack :public Stack<T>
{
public:
  void Push(T element);
    T Pop();
    T top();
    bool isEmpty();
    ~MyStack();
};

template<class T>
MyStack<T>::~MyStack() {
    delete[] stackArray;
}

template<class T>
void MyStack<T>::Push(T element) {
    if (stackTop == stackSize - 1) {
        cout << "Stack Overflow" << endl;
        return;
    }
    stackArray[++stackTop] = element;
}

template<class T>
T MyStack<T>::Pop() {
    if (stackTop == -1) {
        cout << "Stack Underflow" << endl;
        return T();
    }
    return stackArray[stackTop--];
}

template<class T>
T MyStack<T>::top() {
    if (stackTop == -1) {
        cout << "Stack is Empty" << endl;
        return T();
    }
    return stackArray[stackTop];
}

template<class T>
bool MyStack<T>::isEmpty() {
    return stackTop == -1;
}```
#

no instance of constructor "MyStack<T>::MyStack [with T=char]" matches the argument listC/C++(289)
infixToPostfix.h(31, 33): argument types are: (int) this is error

warm sinew
#

MyStack seems to have no constructor that would take an int

#

But what's the definition of Stack

lime valve
#
#include<iostream>
using namespace std;

template<class T>
class Stack {
protected:
    T* stackArray;
    int stackTop;
    int stackSize;
public:
    Stack(int size);
   virtual ~Stack()=0;
   virtual void Push(T element)=0;
   virtual T Pop()=0;
   virtual T top()=0;
    virtual bool isEmpty()=0;
};

template<class T>
 
Stack<T>::Stack(int size) {
    stackArray = new T[size];
    stackTop = -1;
    stackSize = size;
}```
#

I send you a full program

#

#include "MyStack.h"

template<class T>
class CharStack : public Stack<T> {
public:
    CharStack(int size) : Stack<T>(size) {}
    ~CharStack() {}
    void Push(T element) {
        Stack<T>::Push(element);
    }
    T Pop() {
        return Stack<T>::Pop();
    }
};
warm sinew
#
#

Your code doesn't compile for me for a lot of other reasons

lime valve
#

Tell me my mistakes in this code

lime valve
#

Only one line
Line is MyStack<char> operatorStack(length);