c++ - 错误 C2512 : 'Tile' : no appropriate default constructor available

标签 c++ default-constructor

即使使用默认构造函数仍然有错误。

class Foo {
    public:
    Foo ( int x, int y, int type );
}

在 .cpp 文件中

Foo::Foo ( int x = 0, int y = 0, int type = 0 ) {

然而,当我调用它时

Foo foo_array[5][5];

我得到了错误。这可能是什么原因?

最佳答案

将默认参数放在构造函数的声明中。实际上,当您尝试创建数组时,编译器并不知道它们。

关于c++ - 错误 C2512 : 'Tile' : no appropriate default constructor available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14991883/

相关文章:

c++ - ANSI C 89 和 C++ 支持的 C 有什么区别?

c++ - 如何合并两个不同结构的容器( vector/列表),但在 C++ 中有一个公共(public)参数

c++ - 使用 const 字符串时创建默认构造函数

java - 非常简单的构造函数问题,我就是无法得到。 java

c++ - 显式默认构造函数做什么?

java - 这段java继承代码有什么问题?

c++ - 快速大数平方计算

C++11 无锁单生产者单消费者 : how to avoid busy wait

c++ - 使用 LLVM pass 添加内在函数

c++ - Object b(); 有什么区别?和对象 b;?