declare template friend function of template class

You need a few forward declarations:

template <typename T>
class Obj;

template <typename T>
Obj<T> make_obj(T t);

template <typename T>
class Obj {
    T & t;
    Obj (T & t) : t(t) { }
    Obj() = delete;

    friend Obj make_obj<T>(T t);

template <typename T>
Obj<T> make_obj(T t) { 
    return Obj<T>(t);

live example

And BTW: I don’t think you really want T & t; for your class’ member variable. Probably T t; is a better choice 😉

Leave a Comment