"template<>" vs "template" 不带括号 - 有什么区别?
"template<>" vs "template" without brackets - what's the difference?
假设我已经声明:
template <typename T> void foo(T& t);
现在,有什么区别
template <> void foo<int>(int& t);
和
template void foo<int>(int& t);
语义上?没有括号的模板和空括号的模板在其他上下文中有其他语义吗?
相关:如何强制实例化C++模板的特定实例?
template <> void foo<int>(int& t);
声明了模板的专门化,可能具有不同的主体。
template void foo<int>(int& t);
会导致模板的显式实例化,但不会引入专门化。它只是强制实例化特定类型的模板。
使用类/结构,
template <typename T> struct foo {};
以下是专业化:
template <> struct foo<int>{};
以下是一个显式实例化:
template struct foo<int>;
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 警告处理为错误这里有什么问题
- 什么时候调用组成单元对象的析构函数
- 表示"accepting anything for this template argument" C++概念的通配符
- #定义c-预处理器常量..我做错了什么
- 传递给std::function template的template参数究竟代表什么
- C++ 中的"template <typename From, typename Tag> struct Alias;"是什么?
- "template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >"=是什么意思?
- "template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }"定义的含义是什么?
- 声明中的类名后面再次<>什么?...template<B,C>class D<C,B>{}
- "template<>" vs "template" 不带括号 - 有什么区别?
- 在C++中,unordered_map::template和unordered_map::insert之间有什么区别
- "unspecialized class template can't be used as a template argument"是什么意思?
- 没有参数的模板类"template<>"是什么意思?
- "missing template argument"是什么意思?
- 错误:'template'之前的预期主要表达式 - 我做错了什么?
- 模板参数的template-parameter-list是什么意思?
- "use of class template requires template argument list"是什么意思?
- 那么,是什么区别了template(c.end(),_1)和template_back(_1)呢
- 什么是"template<class T> using owner = T;"?