Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pointer to a function needs ; after definition

void (*pf)(int i){
};

According to C++11 I don't need a trailing ';', but Dev-C++ not only throws a Warning - but an Error and breaks compiling.

But if I'd declare

void pf(int i){
}

no warning is thrown anymore?

like image 449
Starhowl Avatar asked Sep 17 '26 17:09

Starhowl


1 Answers

The two things you've shown are vastly different.

void (*pf)(int i){
};

The above defines pf as a pointer to a function taking an int and returning void, and values initializes it. The semi-colon is required. It's the same as

void (*pf)(int i) = nullptr;

In the second snippet

void pf(int i){
}

pf is a function taking an int and returning void.

I'm guessing your version of Dev-C++ doesn't support C++11's uniform initialization syntax. The following should work

void (*pf)(int i) = NULL;
like image 153
Praetorian Avatar answered Sep 20 '26 07:09

Praetorian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!