小编Xom*_*9ik的帖子

无法在复制构造函数中初始化数组

我上课了

class TTable
{
private:
    std::string tableName;
public:
    TRow rows[10]; //this other class TRow
    TTable(const TTable&);
    int countRows = 0;
};
Run Code Online (Sandbox Code Playgroud)

我实现了复制构造函数

TTable::TTable(const TTable& table) : tableName(table.tableName), countRows(table.countRows), rows(table.rows) 
{
    cout << "Copy constructor for: " << table.GetName() << endl;
    tableName = table.GetName() + "(copy)";
    countRows = table.countRows;
    for (int i = 0; i < 10; i++)
    {
        rows[i] = table.rows[i];
    }
}
Run Code Online (Sandbox Code Playgroud)

但编译器会对此进行诅咒rows(table.rows).如何初始化数组?随着变量一切顺利,一切都很好.谢谢.

c++ constructor copy-constructor

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

标签 统计

c++ ×1

constructor ×1

copy-constructor ×1