I am writing code where the return type of the function is quite complex. I would like to use auto to infer from the return type, but this is clearly not possible in a forward declaration. Therefore, I was hoping to at least duplicate the contents of the return statement and do the following:
int q = 5; // veeery complicated type /* Declaration - the best we can do */ auto f() -> decltype(q); /* Later, in a different file */ auto f() { return q; }
This results in the following error in GCC 7,
error: ambiguating new declaration of 'auto f()' note: old declaration 'int f()'
Of course I could repeat
auto f() -> decltype(q) { return q; }
in the definition (which works), but why do I need it when the return type is already uniquely specified by the return ? How is type f in my definition ultimately more ambiguous than int f() ?
source share