How to prevent non-specialized template instantiation?(如何防止非专业模板实例化?)
问题描述
我有一个模板化的class
(称之为Foo
),它有几个专门化.如果有人尝试使用 Foo
的非专业版本,我希望编译失败.
I have a templated class
(call it Foo
) which has several specializations. I would like the compilation to fail if someone tries to use an unspecialized version of Foo
.
这是我实际拥有的:
所以:
同时工作:
没有.
显然,编译器链只会在链接过程发生时发出警告.但是有没有办法让它在之前抱怨?
Obviously, the compiler chain only complains when the linking process takes place. But is there a way to make it complain before ?
我可以使用boost
.
推荐答案
不要定义类:
为什么会这样?仅仅是因为没有任何通用模板.声明,是,但未定义.
Why does this work? Simply because there isn't any generic template. Declared, yes, but not defined.
这篇关于如何防止非专业模板实例化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!