+ 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?
4 Answers
+ 15
#include <iostream>
void yay()
{
std::cout << "WORKS!\n";
}
int main()
{
void (*acc)(void);
acc = yay;
return 0;
}
Further reading: Function pointers.
+ 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â ;
0
and can you explain me, what is the mean std:: ?