2014-07-03から1日間の記事一覧

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

C++

#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:</typeinfo></iostream>…