问题
How to declare a variadic template function as a friend?
For example as follows:
template<class T>
class A
{
friend ??? MakeA ??? ; // What should be placed here ???
A(T)
{}
};
template<class T, class... Args>
A<T> MakeA(Args&&... args)
{
T t(std::forward<Args>(args));
return A(t);
}
回答1:
It's quite straightforward. It's simply a template declaration with the added friend
specifier:
template<class T>
class A
{
template<class T1, class... Args>
friend A<T1> MakeA(Args&&... args);
A(T) { }
};
来源:https://stackoverflow.com/questions/21793092/how-to-declare-a-variadic-template-function-as-a-friend