模板类专业化和朋友类[关闭](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>; };模板类专业化和朋友类[关闭](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>; };