fpermissive类constructorstack类:构造函数上的fpermissive

时间:2014-12-10 18:00:37

标签: c++ class gcc

我一直在:

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

我该如何解决?

2 个答案:

答案 0 :(得分:2)

您在此行上创建了一个对象:

stack stos1 = new stack(10);

并且您正尝试使用指针进行初始化,但无法完成。看起来你打算让stos1成为一个指针:

stack* stos1 = new stack(10);

答案 1 :(得分:1)

当然,在生产代码中,您可以像这样修复它:

#include <stack>

std::stack<char> stos;

http://en.cppreference.com/w/cpp/container/stack