I found that this code, relating to different types of function markup, unexpectedly compiles, despite seemingly invalid. How can this be compiled? Is this a bug in the compiler? I am using gcc 4.8.2 on Ubuntu 14.04.
int addInt(int n,int m)
{
return n+m;
}
int (*(*functionFactoryPtr)(int n))(int, int);
int (*(functionFactory)(int n))(int, int)
{
std::cout << "Got parameter" << n << std::endl;
int (*functionPtr)(int,int) = &addInt;
return functionPtr;
}
int main()
{
std::cout << (******(*****functionFactory)(4))(3,6) << std::endl;
}
source
share