int method1() {
return 0;
}
decltype(method1) method2() {
return method1;
}
I compile my code,get an error: ‘method2’ declared as function returning a function, then I change the return type to function pointer,it works,I just want to why it is so.
decltype(method1) *method2() {
return method1;
}
In C++, functions and arrays cannot be returned. It is how the language is designed.
You have to return either pointer or reference to them. You've already tried with pointer, which works. The following, which returns reference, should also work:
decltype(method1)& method2() {
return method1;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With