【发布时间】:2010-11-11 15:33:02
【问题描述】:
我有一个包含数组“float ** table”的类。现在我想让成员函数返回它,但不希望它在类之外被修改。所以我这样做了:
class sometable
{
public:
...
void updateTable(......);
float **getTable() const {return table;}
private:
...
float **table;
}
当我使用常量对象调用 getTable 时,这编译正常。现在我试着
通过将 getTable 声明为“const float **getTable()”来使其更安全。我有
以下编译错误:
Error:
Cannot return float**const from a function that should return const float**.
为什么?如何避免在课堂外修改表格?
【问题讨论】:
-
Pointer to pointer to 指向.....看起来是个糟糕的设计。这是 C++ - 使用
std::vector并返回引用。