fork download
  1. #include <iostream>
  2.  
  3. void f( void* p, int type )
  4. {
  5. switch( type )
  6. {
  7. case 0: std::cout << *reinterpret_cast<int*>(p); break; // int
  8. case 1: std::cout << *reinterpret_cast<double*>(p); break; // double
  9. //...
  10. }
  11. std::cout << std::endl;
  12. }
  13.  
  14. int main() {
  15.  
  16. int i = 42;
  17. double d = 3.1415;
  18.  
  19. f( &i, 0 ); // ok
  20. f( &d, 1 ); // ok
  21.  
  22. f( &i, 1 ); // ошибка
  23. f( &d, 0 ); // ошибка
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
42
3.1415
-610.304
-1065151889