Is it possible to prevent a C++ template being used without specialization?
For example, I have
template<class T>
void foo() {}
And I don’t want it to be used without being specialized for foo<int> or foo<char>.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be able to declare the function without actually defining it in the generic case. This will cause a reference to an unspecialized template to emit an Undefined Symbol linker error.
This works just fine for me with
clang++.