Declaring functions
From Cppreference
This section is incomplete |
void: A function type that returns nothing
[edit] Example 1
void function() { std::cout << "Hello, World!" << std::endl; //no return }
Output:
Hello, World!
void*: A pointer to the type void
[edit] Example 2
#include <iostream> void print(void* p, char c) { if ( c == 'i' ) { std::cout << "*p = " << *static_cast<int*>(p) << std::endl; } else if ( c == 'c' ) { std::cout << "*p = " << *static_cast<char*>(p) << std::endl; } else if ( c == 's' ) { std::cout << "*p = " << static_cast<char*>(p) << std::endl; } } int main() { int i = 3; char c = '4'; char s[] = "5"; void* pi = &i; void* pc = &c; void* ps = &s; void* pf = reinterpret_cast<void*>(&print); reinterpret_cast<void(*)(void*, char)>(pf)(pi, 'i'); reinterpret_cast<void(*)(void*, char)>(pf)(pc, 'c'); reinterpret_cast<void(*)(void*, char)>(pf)(ps, 's'); }
Output:
*p = 3 *p = 4 *p = 5