キーワードの後のconst
暗黙的なthis
パラメータ(メソッドを呼び出すために使用されたオブジェクトのアドレスに設定されている)が定数オブジェクトを指していることを意味します。
C++。 Cアナログがそれぞれstruct Foo *
とconst struct Foo *
に、アクセスするための関数だろう
class Foo {
int x;
mutable int y;
public:
void bar() {
Foo *me = this; // * this is an implicit parameter
// that points to the instance used
// to call bar()
assert(&x == &this->x); // * accesses to class members are
// implicitly taken from this
x = 1; // * can modify data members
}
void bar() const {
// Foo *me = this; // * error, since "bar() const" means
// this is a "const Foo *"
const Foo *me = this; // * ok
// x = 1; // * error, cannot modify non-mutable
// members of a "const Foo"
y = 0; // * ok, since y is mutable
}
};
:メンバ関数は次のようになり
struct Foo {
int x;
int y;
};
void Foo_bar (Foo *this) { /* ... */ } /* can modify this->x and this->y */
void cFoo_bar (const Foo *this) { /* ... */ } /* cannot modify this->x nor this->y */
C.
には
mutable
アナログ
出典
2013-07-24 02:43:46
jxh
HTTPはありません://stackoverflow.com/questions/15999123/const-before-parameter-vs-const-after-function-name-c – chris
または[this](http://stackoverflow.com/questions/3141087/what-is-機能終了宣言を伴う意味) – aaronman
@chrisいいですね。しかし、今私は混乱しています。 'GetSelectedCells'関数は変更するパラメータがありません。 – itsols