我一直在:
../src/stack.cpp: In function ‘int main()’:
../src/stack.cpp:34:28: error: invalid conversion from ‘stack*’ to ‘int’ [-fpermissive]
stack stos1 = new stack(10);
^
../src/wieze-oig.cpp:10:2: error: initializing argument 1 of ‘stack::stack(int)’ [-fpermissive]
stack(const int size){
initializing argument 1 of ‘stack::stack(int)’ [-fpermissive]
关于此代码:
class stack
{
int stacksize;
stack(const int size)
{
this->stacksize = size;
this->data = new char[stacksize];
this->ctr = 0;
}
}
我该如何解决?
答案 0 :(得分:2)
您在此行上创建了一个对象:
stack stos1 = new stack(10);
并且您正尝试使用指针进行初始化,但无法完成。看起来你打算让stos1
成为一个指针:
stack* stos1 = new stack(10);
答案 1 :(得分:1)
当然,在生产代码中,您可以像这样修复它:
#include <stack>
std::stack<char> stos;