Modified the question a bit, thanks for your help on this!
Is there a way to change Parent's constructor(e.g. change the value of protected field) when initialize the Child class.
For example, I have two class - Base and Child below. In the Base constructor, string 'a' will be assigned to a protected field - 'a_' and 'val'(e.g. if a is "str", then a_ is 'a', val is 'a!').
There is a Child class that inherits class Base, and the constructor takes two arguments - string a and b.
What I want is assign 'a+b+"!"' to val, e.g. a = "first ", b = "second", then a_ is "first", b_ is "second", c's value should be "first second!"
class Base {
public:
explicit Base(string a) : a_(a), val(a + "!"){};
protected:
string a_;
string val;
}
class Child : public Base {
public:
explicit Child(String a, String b) : Base(a), b_(b)...
protected:
string b_;
}