c++ - How to use `using space::function` in class declaration scope? -


i use using declaration enable adl on specific function lookup can use in constructor initialization list.

here code:

template< typename t > struct refwrapper {     refwrapper(t& t)     : w(t)     {}      t& w; };  struct val {     val(refwrapper<val> rw)     {/*...*/} };  namespace x {     template< typename t >     refwrapper<t> makewrap(t& t)     { return refwrapper<t>(t); } }  namespace y {     using x::makewrap;  // god no !     struct c     {         //using x::makewrap;  // want here         //                     error: using-declaration non-member @ class scope          c(val& value) : member(makewrap(value))         {}          val member;     }; } 

related:
how narrow should using declaration be?
in question's unique's answer, (4) impossible, place want !

unfortunately, can't that.

n4527::7.3.3$3, using declaration, [namespace.udecl]:

in using-declaration used member-declaration, nested-name-specifier shall name base class of class being defined.

of course, can explicitly appoint nested-name-specifier like:

c(val& value) : member(x::makewrap(value)) 

or workaround, can use local wrapper function, this:

struct c {     //using x::makewrap;  // want here     //                     error: using-declaration non-member @ class scope      c(val& value) : member(makewrap(value))     {}      val member; private:     template< typename t >     t makewrap(t& t) { return x::makewrap(t); }  }; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -