私は、配列 "float ** table
"を保持するクラスを持っています。今、私はそれを返すメンバ関数を持っているが、クラスの外でそれを変更したくない。だから私はこれをやった:C++関数からconst Float **を返す方法
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**.
なぜですか?どのようにしてクラスの側面から修正するテーブルを避けることができますか?ご希望の場合は
float const* const* getTable() const {return table;}
または
const float* const* getTable() const {return table;}
:
ポインターへのポインター.....悪いデザインのように見えます。これはC++です - 'std :: vector'を使って参照を返します。 –