很抱歉这个问题的标题有多复杂; 我试图描述我为这个问题构建的最小SSCCE.
我有以下代码:
#include <iostream>
namespace fizz
{
template<typename... Ts>
class bar
{
public:
template<int I, typename... Us>
friend auto foo(const bar<Us...> &);
private:
int i = 123;
};
template<int I, typename... Ts>
auto foo(const bar<Ts...> & b)
{
return b.i;
}
}
int main()
{
std::cout << fizz::foo<1>(fizz::bar<int, float>{});
}
Run Code Online (Sandbox Code Playgroud)
此代码使用GCC 5.2进行编译,而不是使用Clang 3.7进行编译:
main.cpp:19:18: error: 'i' is a private member of 'fizz::bar<int, float>'
return b.i;
^
main.cpp:25:24: note: in instantiation of function template specialization …Run Code Online (Sandbox Code Playgroud)