派生クラスを指すPlayer
メンバー変数を持つクラスがあります。Creature *character
Elf : public Creature
Player
オブジェクトを宣言して、そのメンバーの 1 つを にポイントさせ、情報を取得できるようにしたいと考えていElf
ます。
データ メンバーは非公開にする必要があることは理解していますが、これは特殊なケースですか、それとも関数Elf
からメンバーから情報を取得するにはどうすればよいですか?main
void Player::set_character(Creature &c)
{
character = &c;
}
...
Player me;
Elf me_elf;
me.set_character(me_elf);