quot;templatelt;gt;quot; vs quot;templatequot; without brackets - what#39;s the difference?(“模板与“模板没有括号 - 有什么区别?)
问题描述
假设我已经声明:
template <typename T> void foo(T& t);
现在,
template <> void foo<int>(int& t);
和
template void foo<int>(int& t);
语义上?不带括号的模板和带空括号的模板在其他上下文中是否有其他语义?
semantically? And do template-with-no-brackets and template-with-empty-brackets have other semantics in other contexts?
相关:如何强制实例化 C++ 模板的特定实例?
推荐答案
template <>void foo<int>(int& t);
声明模板的特殊化,可能具有不同的主体.
template <> void foo<int>(int& t);
declares a specialization of the template, with potentially different body.
template void foo
导致模板的显式实例化,但不引入特化.它只是强制为特定类型实例化模板.
template void foo<int>(int& t);
causes an explicit instantiation of the template, but doesn't introduce a specialization. It just forces the instantiation of the template for a specific type.
这篇关于“模板"与“模板"没有括号 - 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“模板"与“模板"没有括号 - 有什么区别


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01