c – 本身就是模板的专业化

c – 本身就是模板的专业化,第1张

概述我有一个模板类,我有一些专长. 但下一个专业化是一个模板本身.你如何指定: template<typename T>class Action{ public: void doStuff() { std::cout << "Generic\n"; }}// A specialization for a persontemplate<>class Action<Person> 我有一个模板类,我有一些专长.
但下一个专业化是一个模板本身.你如何指定:
template<typename T>class Action{    public: voID doStuff()  { std::cout << "Generic\n"; }}// A specialization for a persontemplate<>class Action<Person>{    public: voID doStuff()  { std::cout << "A Person\n";}}// I can easily specialize for vectors of a particular type.// But how  do I change the following so that it works with all types of vector.// Not just `int`template<>class Action<std::vector<int> >{    public: voID doStuff()  { std::cout << "A Generic Vector\n";}}
解决方法 琐碎的部分专业化?
template <typename T>class Action<std::vector<T>> {public:  voID doStuff() { std::cout << "A Generic Vector\n"; }};
总结

以上是内存溢出为你收集整理的c – 本身就是模板的专业化全部内容,希望文章能够帮你解决c – 本身就是模板的专业化所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1254308.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-07
下一篇2022-06-07

发表评论

登录后才能评论

评论列表(0条)

    保存