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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -