gpt4 book ai didi

c++ - fpermissive 类构造函数堆栈类 : fpermissive on constructor

转载 作者:行者123 更新时间:2023-11-28 00:21:07 25 4
gpt4 key购买 nike

我不断得到:

../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;
}
}

我该如何解决?

最佳答案

您正在这一行创建一个对象:

stack stos1 = new stack(10);

而你试图用一个指针来初始化它,这是不可能的。看起来你打算让 stos1 成为一个指针:

stack* stos1 = new stack(10);

关于c++ - fpermissive 类构造函数堆栈类 : fpermissive on constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com