try_pointer.hpp 321 B

123456789101112131415
  1. #include <iostream>
  2. // Void pointer can be pointed to any data type
  3. void print(void *ptr, char type)
  4. {
  5. switch (type)
  6. {
  7. case 'i':
  8. std::cout << (*(int *)ptr) << std::endl;
  9. break; //handle *int
  10. case 'c':
  11. std::cout << (*(char *)ptr) << std::endl; //handle *char
  12. break;
  13. }
  14. }