Home >Backend Development >C++ >Why Does Partial Specialization of a Template Function Member Cause 'Invalid Use of Incomplete Type'?
"Invalid Use of Incomplete Type" Error in Partial Template Specialization
When attempting to create a partial specialization of a template function with the syntax:
template <typename T> void foo<int, T>::bar() { }
you may receive the error "invalid use of incomplete type 'struct foo
To resolve this, specify the complete template signature when partially specializing the class:
template <typename S, typename T> struct foo { void bar(); }; template <> struct foo<int, T> { void bar() { } };
Alternatively, you can use a workaround such as creating a nested template struct or deriving from another template that partially specializes.
Note: This applies only to partial specialization of member functions. Fully specializing a template function does not require specializing the entire template.
The above is the detailed content of Why Does Partial Specialization of a Template Function Member Cause 'Invalid Use of Incomplete Type'?. For more information, please follow other related articles on the PHP Chinese website!