模板类专业化和朋友类[关闭](Template class specialization and friend classes [closed])

编程入门 行业动态 更新时间:2024-10-12 16:24:36
模板类专业化和朋友类[关闭](Template class specialization and friend classes [closed])

我遇到以下情况:

template<typename T, int N> class Foo { }; // specialization for 0 template<typename T> class Foo<0> { friend class Foo<T, 1>; };

也就是说,我需要Foo<T, 1>是Foo<T, 0>朋友,但我有编译错误。 这可能吗?

I am in the following situation:

template<typename T, int N> class Foo { }; // specialization for 0 template<typename T> class Foo<0> { friend class Foo<T, 1>; };

That is, I need that Foo<T, 1> is friend of Foo<T, 0>, but I have a compiler error. Is this possible?

最满意答案

你的专业化有一个错字:

template<typename T> class Foo<T, 0> { // ^^^ <= add this friend class Foo<T, 1>; };

You have a typo in your specialization:

template<typename T> class Foo<T, 0> { // ^^^ <= add this friend class Foo<T, 1>; };

更多推荐

本文发布于:2023-08-08 01:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类专业   模板   朋友   Template   class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!