#include "stdafx.h"

#include <iostream>
#include <typeinfo>

using namespace std;

class Base {};
class Derived : public Base {};

int main( ) {

	Base b, bb;
	Derived d;

	// Use typeid to test type equality
	if (typeid(b) == typeid(d)) { // No
		cout << "b and d are of the same type.\n";
	}
	if (typeid(b) == typeid(bb)) { // Yes
		cout << "b and bb are of the same type.\n";
	}
	if (typeid(d) == typeid(Derived)) { // Yes
		cout << "d is of type Derived.\n";
		cout<<typeid(d).name()<<endl;
	}
}

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2021-09-12
  • 2021-07-30
  • 2022-12-23
  • 2021-09-04
  • 2021-10-19
猜你喜欢
  • 2021-11-10
  • 2022-01-10
  • 2022-12-23
  • 2021-09-13
相关资源
相似解决方案