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.
24 messages · Page 1 of 1 (latest)
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.
We can only help if you send the error message
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
MyStack<char> operatorStack(length);
This line giving the error
Show the definition of MyStack
#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
MyStack seems to have no constructor that would take an int
But what's the definition of Stack
#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();
}
};
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) {
stackArra...
Your code doesn't compile for me for a lot of other reasons
Tell me my mistakes in this code
Compiler giving compile time error
Only one line
Line is MyStack<char> operatorStack(length);