What does “In instantiation of … required from here” mean?

前端 未结 1 562
暗喜
暗喜 2021-02-07 10:11

I get the following compiler¹ message

main.cpp: In instantiation of ‘void fkt(Foo) [with Foo = int]’:
main.cpp:5:7:   required from here

The bi

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-07 10:39

    main.cpp: In instantiation of ‘void fkt(Foo) [with Foo = int]’:
    main.cpp:5:7:   required from here
    main.cpp:2:6: warning: unused parameter ‘f’ [-Wunused-parameter]
    

    This is all one warning. You are getting a 3 line warning about an unused parameter. The first two lines are the compiler attempting to help you identify the cause of the warning. Here's an English translation:

    In the instantiation of fkt with template argument Foo as int which was required by line 5 column 7, you have an unused parameter called f.

    fkt is a function template. Templates have to be instantiated with the given template arguments. For example, if you use fkt, the fkt function template is instantiated with Foo as int. If you use fkt, the fkt function template is instantiated with Foo as float.

    In particular, this first line of this message is telling you that the warning occurs inside fkt which was instantiated with Foo as int. The second line of the warning tells you that instantiation occurred on line 5. That corresponds to this line:

    fkt(1);
    

    This is instantiating fkt with Foo as int because the template argument Foo is being deduced from the type of the argument you're giving. Since you're passing 1, Foo is deduced to be int.

    0 讨论(0)
提交回复
热议问题