Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a reference to a function or what?

Tags:

c++

What does the following declaration mean?

typedef int (&rifii) (int,int);

Is it a reference to a function? If yes, shouldn't it be initialized?

like image 733
bhuwansahni Avatar asked Aug 31 '26 20:08

bhuwansahni


1 Answers

It defines the type "reference to a function taking two ints and returning an int". Variables of that type need be initialized, but you can't put an initializer into a typedef. It's not different to e.g. int:

int i;

typedef int& intref; // no initializer allowed
intref ri(i); // initializer required

int f(int, int);

typedef int (&rifii) (int,int); // no initializer allowed
rifii rf(f); // initializer required
like image 133
celtschk Avatar answered Sep 02 '26 10:09

celtschk



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!