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 {
private:
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 😉
Related Contents:
- overloading friend operator
- std::enable_if to conditionally compile a member function
- C++11 does not deduce type when std::function or lambda functions are involved
- C++ template typedef
- initializer_list and move semantics
- Variadic template pack expansion
- SFINAE working in return type but not as template parameter
- How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?
- using extern template (C++11)
- What exactly is the “immediate context” mentioned in the C++11 Standard for which SFINAE applies?
- std::function vs template
- initializer_list and template type deduction
- What is “Expression SFINAE”?
- How to declare a templated struct/class as a friend?
- static_assert fails compilation even though template function is called nowhere
- Specifying one type for all arguments passed to variadic function or variadic template function w/out using array, vector, structs, etc?
- Selecting a member function using different enable_if conditions
- How to initialize std::array elegantly if T is not default constructible?
- Why should I avoid std::enable_if in function signatures
- What is the easiest way to print a variadic parameter pack using std::ostream?
- Default template argument when using std::enable_if as templ. param.: why OK with two template functions that differ only in the enable_if parameter?
- Template tuple – calling a function on each element
- Calling a function for each variadic template argument and an array
- What is the partial ordering procedure in template deduction
- When to use std::forward to forward arguments?
- C++11: I can go from multiple args to tuple, but can I go from tuple to multiple args? [duplicate]
- trailing return type using decltype with a variadic template function
- Variadic function template with pack expansion not in last parameter
- Alias template specialisation
- What do compilers do with compile-time branching?
- Is it possible to “store” a template parameter pack without expanding it?
- Parameter pack must be at the end of the parameter list… When and why?
- How do compilers treat variable length arrays
- Can lambda functions be templated?
- Lambda expressions as class template parameters
- C++11: Compile Time Calculation of Array
- How to pass a template function in a template argument list
- Is there a compiler bug exposed by my implementation of an is_complete type trait?
- Populate An Array Using Constexpr at Compile-time
- How can I expand call to variadic template base classes?
- Template specialization and enable_if problems [duplicate]
- SFINAE works differently in cases of type and non-type template parameters
- Doing a static_assert that a template type is another template
- C++ template friend operator overloading
- How can I output the value of an enum class in C++11
- Making a template parameter a friend?
- Forwarding all constructors in C++0x
- Can the point-of-instantiation be delayed until the end of the translation unit?
- friend declaration declares a non-template function [duplicate]
- using extern template (C++11) to avoid instantiation