C++相談室 part31
■ このスレッドは過去ログ倉庫に格納されています
0459デフォルトの名無しさん
NGNG{
protected:
int a;
public:
int GetA() const { return a; }
void SetA(int a) { this->a = a; }
};
class B : public A
{
protected:
double b;
public:
};
このようなクラス関係で
B bInstance[100];
bInstance[1].SetA(50);
const A* ptr = bInstance;
++ptr;
int result = ptr->GetA();
とやるとポリモーフィズムでresultに50が入ると思うのですが、
実際には正しい値が得られません。
どこがおかしいのでしょうか?ご教授下さい。
■ このスレッドは過去ログ倉庫に格納されています