什么是“在实例化...需要从这里“的意思
What does “In instantiation of … required from here” mean?
我收到以下编译器¹消息
main.cpp: In instantiation of ‘void fkt(Foo) [with Foo = int]’:
main.cpp:5:7: required from here
无论如何都会创建二进制文件,因此这不是错误。但它也是未标记为警告。这是什么消息,为什么我会收到它?
我将代码简化为以下示例
template <typename Foo>
void fkt(Foo f) {}
int main() {
fkt(1);
return 0;
}
¹ 海湾合作委员会 4.7.2
编辑:这里是重现的步骤:
% cat main.cpp
template <typename Foo>
void fkt(Foo f) {}
int main() {
fkt(1);
return 0;
}
% g++ -Wall -Wextra main.cpp
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]
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]
这都是一个警告。您收到有关未使用参数的 3 行警告。前两行是编译器,试图帮助您确定警告的原因。以下是英文翻译:
在实例化带有模板参数的
fkt
Foo
为第 5 行第 7 列所需的int
时,您有一个名为f
的未使用参数。
fkt
是一个函数模板。模板必须使用给定的模板参数进行实例化。例如,如果使用 fkt<int>
,则fkt
函数模板实例化时Foo
为 int
。如果使用 fkt<float>
,则fkt
函数模板将实例化为 Foo
作为float
。
特别是,此消息的第一行告诉您警告发生在fkt
内部,该警告已实例化Foo
作为int
。警告的第二行告诉您实例化发生在第 5 行。这对应于这一行:
fkt(1);
这是实例化fkt
Foo
作为int
,因为模板参数Foo
是从您给出的参数类型推断出来的。既然你通过1
,Foo
就被推论为int
。
相关文章:
- 警告处理为错误这里有什么问题
- 努力将整数转换为链表。不知道我在这里做错了什么
- 这个语法std::class<>{}(arg1, arg2) 在C++中是什么意思?
- 这里在 Linux 中具有"CreatePipe"和"CreateProcessW"功能吗?
- 标准 N3337 5.2.10 第 7 条中的C++"类型"是什么意思?
- "类模板示例<int>;"语句对 C++11 是什么意思?
- 线应该是什么意思
- 错误:无效的预处理指令 #i 的意思是 #if?
- "CID"在AT+HTTPPARA= "CID" ,1中是什么意思
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 表达式"b=(b-x)&x"是什么意思?
- 当我从下面的代码中删除关键字 virtual 时,它可以正常工作,否则会出现错误。在这里"virtual"字的意义是什么?
- 这个表达是什么意思?
- 此代码验证公式是什么意思?
- 这里的字符串函数是什么意思
- "cin.exceptions"和"exception"在这里是什么意思
- {错误 C2338: (boost::has_trivial_destructor:<T>:value)} 对于 boost::lockfree::queue 是什么意思?我在这里错过了什
- 什么是“在实例化...需要从这里“的意思
- SAFE[]在这里是什么意思
- 这里UserArray是什么意思