Program Pointer
Contoh program pointer
#include <iostream> using namespace std; enum Type { INT, FLOAT, STRING, }; void Display(void *pVoid, Type eType) { switch (eType) { case INT: cout << *(int*)pVoid << endl; break; case FLOAT: cout << *(float*)pVoid << endl; break; case STRING: cout << (char*)pVoid << endl; break; } } int main() { int a = 10; float b = 987.654; char *c = "Art is a lie that makes us realize the truth."; Display(&a, INT); Display(&b, FLOAT); Display(c, STRING); return 0; }
0 komentar:
Post a Comment