Making a template parameter a friend?

前端 未结 3 1601
忘掉有多难
忘掉有多难 2020-12-01 04:31

Example:

template
class Base {
public:
    Base();
    friend class T;
};

Now this doesn\'t work... Is there a way of doing

3条回答
  •  醉话见心
    2020-12-01 05:01

    I found a simple trick to declare template parameters as friends:

    template < typename T>
    struct type_wrapper 
    { 
       typedef T type; 
    }; 
    
    
    template < typename T> class foo 
    { 
      friend class type_wrapper < T>::type 
    };   // type_wrapper< T>::type == T
    

    However I do not know how this could help to define an alternative version of a class sealer.

提交回复
热议问题