+ 4

C++ Pointers to void?

i want to access void function with pointer. like this #include <iostream> using namespace std; void yay() {cout << "WORKS!\n";} int main() { void *acc; acc = yay(); //now i want yay is called and produce ouput return 0; } but of course its occur an error. how to do that?

20th Dec 2017, 11:51 AM
Kevin AS
Kevin AS - avatar
4 Respuestas
+ 15
#include <iostream> void yay() { std::cout << "WORKS!\n"; } int main() { void (*acc)(void); acc = yay; return 0; } Further reading: Function pointers.
20th Dec 2017, 12:01 PM
Hatsy Rei
Hatsy Rei - avatar
20th Dec 2017, 1:02 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
std:: is the Standard call for c++ output. So if you use “using namespace std;” you wouldn’t have to use std::cout, you would just say cout << “hi” ;
21st Dec 2017, 5:29 PM
Aiden Yi
Aiden Yi - avatar
0
and can you explain me, what is the mean std:: ?
20th Dec 2017, 12:30 PM
Kevin AS
Kevin AS - avatar