我有一個接口C++模板:防止基本模板的實例
std::string
get_string(Source const &s, std::string const &d);
int
get_int(Source const &s, int const &d);
bool
get_bool(Source const &s, bool const &d);
我想改變
template<class T>
T
get(Source const &s, T const &d);
但其中有沒有合理的基礎模板,所以實際的基礎定義是合法但無用的(return d;
)。如果基礎實例化,我能做些什麼來強制編譯時失敗?這種情況是否有一種習慣解決方案?
* base模板*是什麼意思?另外請記住,功能模板不專門化,但過載。 – 2010-01-12 17:30:41
「基本模板」與「專業化」相對 – 2010-01-12 18:14:45
如果您不想定義「基本模板」,則無需向模板中添加模板。你最初的想法是爲各種類型提供重載是正確的。 – 2010-01-12 19:00:04