小编Shr*_*ant的帖子

没有默认构造函数的类

我们可以创建一个没有默认构造函数的类对象数组,如果是,那么任何人都可以详细说明我们如何做到这一点?

对于main()中的Abc a [10]的后续类; 正在生成编译器错误'没有匹配函数来调用`Abc :: Abc()'

class Abc{
    private: 
           int x;
    public:
           Abc(int a){
           x = a;
           }
};

int main(){
    Abc a[10]; // Compilation would fail here, as it would look for default constructor
}
Run Code Online (Sandbox Code Playgroud)

c++ constructor

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

标签 统计

c++ ×1

constructor ×1