どの派生クラスのオブジェクトが代入されているかを調べる

#include <iostream>
#include <typeinfo>

struct Base {
    virtual void member_function() {} // 仮想関数を持たせておく必要がある
};
struct Derived : public Base {};

int main()
{
    Base* p = new Derived();

    if (typeid(*p) == typeid(Base)) {
        std::cout << "Base" << std::endl;
    }
    if (typeid(*p) == typeid(Derived)) {
        std::cout << "Derived" << std::endl;
    }
}

出力:

Derived