c++ - Hiding implementation details of base class from derived class -



c++ - Hiding implementation details of base class from derived class -

say have base of operations class , derived b class:

struct { a(int a) : a(a) {} int a; }; struct b : public { b(int a, int b) : a(a), b(b) {} int b; };

is there way define b class without knowing class' constructor? instance mill class may responsible providing info class needs writter of b class doesn't have know it. assuming don't delegate constructors possible first initialize class part of object , initialize b part using set of constructor arguments?

you utilize variadic templated constructor can forwards arguments base of operations class [1]

struct b : public { template<typename...ts> b(int b, ts&&...args) : a(std::forward<ts>(args)...), b(b) { } int b; };

but above not of practical utilize unless [2] base of operations class generic aspect, eg

template<typename base> struct b : public base of operations { template<typename...ts> b(int b, ts&&...args) : base(std::forward<ts>(args)...), b(b) { // above initialization of b (its related argument) // not part of variadic pack } int b; };

example

1. above imply related mill method uses variadic templates

2. considering class wants build base of operations without knowing how many or type of variables it's constructed from. uses may vary depending on context

c++ constructor

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -