繁体   English   中英

C++ 如果我编写一个 function 模板并且不请求它的任何实例化,是否会从中生成任何模板函数?

[英]C++ If I write a function template and don’t request any instantiations of it, will any template functions be generated from it?

只是问了一个我在我阅读的教科书的最后一章中一直在思考的问题

“如果我编写一个 function 模板并且不请求它的任何实例化,是否会从中生成任何模板函数?”

我相信它是错误的,因为如果您不通过实例化明确询问,则无法创建模板。 想法?

class 模板本身不是类型,也不是 object 或任何其他实体。

仅包含模板定义的源文件不会生成任何代码。 In order for any code to appear, a template must be instantiated: the template arguments must be provided so that the compiler can generate an actual class (or function, from a function template).

https://en.cppreference.com/w/cpp/language/templates

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM