1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <string>
struct A {
struct Tag{};
std::string name;
int value;
A (const std::string& n, int v) : name(n), value(v) {}
A (const std::string& n, int v, Tag) : name(n), value(v) {std::cout << "Constructor with Tag called.\n";}
};
struct B : A {using A::A;};
struct C : B {using B::B;};
struct D : C {
char special;
D (const std::string& n, int v, char s) : C(n, v), special(s) {}
D (const std::string& n, int v, char s, Tag tag) : C(n, v, tag), special(s) {} // Any way to avoid this repetition?
};
struct E : B {
double special;
E (const std::string& n, int v, double d) : B(n, v), special(d) {}
E (const std::string& n, int v, double d, Tag tag) : B(n, v, tag), special(d) {} // Again the nuissance!
};
int main() {
A a("a", 1, A::Tag{});
B b("a", 2, A::Tag{});
C c("c", 3, A::Tag{});
D d("d", 4, 'd', A::Tag{});
E e("e", 5, 3.14, A::Tag{});
}
|