class Test
{
private:
int a;
template<typename Container>
friend void f1(Container &container);
template<template<typename, typename> class Container, template <typename> class Allocator>
friend void f2(Container<Test, Allocator<Test>> &container);
};
template<typename Container>
void f1(Container &container)
{
Test test;
test.a = 10;
}
template<template<typename, typename> class Container, template <typename> class Allocator>
void f2(Container<Test, Allocator<Test>> &container)
{
Test test;
test.a = 10;
}
int main(int argc, char *argv[])
{
std::vector<Test> v;
f1(v); // Oк
f2(v); // Не ок
return 0;
}
Не работает friend для f2:
Error 2 error C2248: 'Test::a' : cannot access private member declared in class 'Test'
Есть какой-нибудь не сильно ужасный воркараунд? В GCC всё ок.