c++ - Declare a template function as friend -
i have global function this:
namespace x { namespace y { template <r, ...t> r foo(t&&... args) { r r(args...); return r; } } } then in class a, want declare function foo friend of a. did:
class { template <r, ...t> friend r x::y::foo(t&&... args); a(int x, int y){} }; now when, call x::y::foo<a>(4, 5) fails compile error foo can not access private constructor of a. unable understand error, how declare foo friend of a correctly?
thanks in advance.
after fixing syntactic issues template parameters , parameter packs, seems work:
namespace x { namespace y { template <typename r, typename ...t> r foo(t&&... args) { r r(args...); return r; } } } class { template <typename r, typename ...t> friend r x::y::foo(t&&... args); a(int x, int y){} }; int main() { x::y::foo<a>(1, 2); } here live example of above code compiling.
Comments
Post a Comment