基本クラス メソッド内で使用した場合、this ポインターはどのように動作しますか。
class Base{
public:
int a;
Base() : a(5) {}
void func(){
std::cout << " value is : " << this->a << std::endl;
}
};
class Derived : public Base{
private:
int a;
public:
Derived() : a(1){}
void func1(){
std::cout << " value is : " << this->a << std::endl;
}
};
int main(){
Derived d;
d.func();
d.func1();
}
コードの出力は次のとおりです。
値: 5
値: 1
同じオブジェクトを使用して両方の関数を呼び出しているためです。このポインターの値は、基本クラスと派生クラスのメソッドで異なりますか?