Use of 'auto func(int)' before deduction of 'auto' in C++14

后端 未结 4 417
攒了一身酷
攒了一身酷 2020-12-05 13:35

I have compiled following program in GCC using C++14.

#include 
using namespace std;

auto func(int i);

int main() 
{
    auto         


        
4条回答
  •  暖寄归人
    2020-12-05 14:20

    When auto is used as the return type in a function declaration that does not use the trailing return type syntax, the keyword auto indicates that the return type will be deduced from the operand of its return statement. That means the deduction can't be performed until the definition of the function func(), but before that it has been used in main().

    You could move the definition before main(), or use trailing return type syntax to specify the return type on the declaration.

提交回复
热议问题