Question: Declare a pointer to a function taking an int argument and returning a pointer to a function that takes a char argument and returns a float.
I did code as follows. But it is giving error. Please correct this.
#include <iostream>
using namespace std;
float func(int x)(char c) {
cout << "func() called..." << endl;
}
int main() {
int x = 2;
char c;
float (*(*fp)(int))(char); // Define a function pointer
(*fp) = func; // Initialize it
(*(*fp))(x)(c); // Dereferencing calls the function
}
ambarish@ubuntu:~/exercise$ g++ ex33.cpp
ex33.cpp:4: error: ‘func’ declared as function returning a function
ex33.cpp: In function ‘int main()’:
ex33.cpp:13: error: assignment of read-only location ‘* fp’
ex33.cpp:13: error: cannot convert ‘int ()(int)’ to ‘float (* ()(int))(char)’ in assignment
ambarish@ubuntu:~/exercise$