小编Mal*_*ikx的帖子

构造函数定义C++

我在C++中有以下类:

class IntStack
{
    private:
        int *stackArray;
        int stackSize;
        int top;

    public:
        IntStack(int);          // Constructor
        // rest of the 
        // member function
};  
Run Code Online (Sandbox Code Playgroud)

我已经将类外的构造函数定义为:

IntStack::IntStack(int size)
{
    stackArray = new int[size];
    stackSize = size;
    top = -1;
}
Run Code Online (Sandbox Code Playgroud)

这里的错误是: initializing argument 1 of 'IntStack::IntStack(int)

我创建了同一个类的实例:

cout << endl << "Enter size of Stack: ";
cin  >> stackCapacity;
IntStack stack = new IntStack(stackCapacity);
Run Code Online (Sandbox Code Playgroud)

这里的错误是: invalid conversion from 'IntStack*' to 'int' [-fpermissive]

如何理清这些错误?

c++ constructor

0
推荐指数
1
解决办法
93
查看次数

标签 统计

c++ ×1

constructor ×1