How to declare a variadic template function as a friend?

柔情痞子 提交于 2019-11-30 03:50:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!