c++ - Using "using" in public to inherit private constructor does not make it public -


"using" private member variable makes public member constructor stays private. example:

class myclass;  class base {   private:     base(float v) : m_v{v} {}     float m_v;      friend myclass; };  class myclass: public base {   public:     using super = base;      using super::super; // still private     using super::m_v; // public };  int main() {   myclass x{3.4f}; // error - calling private constructor of class 'base'   (void)x.m_v; // not error    return 0; } 

is there other way other writing universal ctor this?

template<typename... args> myclass(args&&... args) : super(std::forward<args>(args)...) {} 

http://en.cppreference.com/w/cpp/language/using_declaration#inheriting_constructors contains following passage :

it has same access corresponding base constructor. constexpr if user-defined constructor have satisfied constexpr constructor requirements. deleted if corresponding base constructor deleted or if defaulted default constructor deleted (except construction of base constructor being inherited doesn't count). inheriting constructor cannot explicitly instantiated or explicitly specialized.

it refers inherited constructor. i'm not sure why, appear approach explicitly forbidden. usual solution define universal forwarding constructor.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -