declare and define function pointer variable in one line

  • A+
Category:Languages

... apologies for the previous one

In C++ how do we do the following

// fundamental language construct            type name = value ;  // for example     int x = y; 

with function pointers?

 typedef (char)(*FP)(unsigned);   // AFAIK not possible in C++  FP x = y ; 

I can use lambdas:

 FP x = []( unsigned k) -> char { return char(k); } 

But I do not know how to do this without lambda. Any ideas?

 


It is almost the same as Lambdas, but hard to read i think:

void my_int_func(int x) {     std::cout << "ther param is: " << x << std::endl; }  // int main(int argc, char *argv[]) {     void (*foo)(int) = my_int_func;     foo(1); 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: