fork(1) download
  1. #include <iostream>
  2. #include <typeinfo>
  3. using namespace std;
  4.  
  5. class A
  6. {
  7. public:
  8. virtual void fV() { }
  9. };
  10. class B : public A
  11. {
  12. public:
  13. void mB() { }
  14. };
  15. class C : public A
  16. {
  17. public:
  18. void mC() { }
  19. };
  20.  
  21. int main() {
  22. A *array[4] = { new A, new C, new C, new B }; // first changed to raw A
  23. cout << "i A B C\n--------"<<endl;
  24. for(int i = 0; i < 4; ++i) {
  25. cout << i + 1 << ". " ;
  26. (typeid(*array[i]) == typeid(A)) ? cout << 1 << ' ': cout << 0 << ' ';
  27. (typeid(*array[i]) == typeid(B)) ? cout << 1 << ' ': cout << 0 << ' ';
  28. (typeid(*array[i]) == typeid(C)) ? cout << 1 << ' ': cout << 0 << ' ';
  29. cout << endl;
  30. }
  31. return 0;
  32. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
i  A B C
--------
1. 1 0 0 
2. 0 0 1 
3. 0 0 1 
4. 0 1 0