I found this question here but now I want to extend it. so I have the following class in one file and it works correctly:
typedef int (*fptr)();
int f1() {
return 1;
}
int f2() {
return 2;
}
fptr f( char c ) {
if ( c == '1' ) {
return f1;
}
else {
return f2;
}
}
But when I want to move the functions in another file and make a factory out of them, I get an error that I cannot understand.
it would be like this:
Header:
public class Factories{
public:
int f1();
int f2();
}
CPPFile:
int f1() {
return 1;
}
int f2() {
return 2;
}
Header:
public class FactoryClass{
public:
fptr f( char c );
}
CPPFile:
typedef int (*fptr)();
fptr f( char c ) {
if ( c == '1' ) {
return Factories::f1;
}
else {
return Factories::f2;
}
}
Here in the returns of this FactoryClass Function I get the error "return value type does not match the function type". Any Ideas would be appreciated.