C++模板上下文中的特化和实例化有什么区别.从我到目前为止所读到的内容,以下是我对专业化和实例化的理解.
template <typename T>
struct Struct
{
T x;
};
template<>
struct Struct <int> //specialization
{
//code
};
int main()
{
Struct <int> s; //specialized version comes into play
Struct <float> r; // Struct <float> is instantiated by the compiler as shown below
}
Run Code Online (Sandbox Code Playgroud)
Struct <float>由编译器实例化
template <typename T=float>
struct Struct
{
float x;
}
Run Code Online (Sandbox Code Playgroud)
我对模板实例化和专业化的理解是否正确?