Код: Выделить всё
class BaseClass {
public:
BaseClass(int a, double b, int c, std::string d) {
// Do stuff depending also on d
}
double f; // Inizialized in the BaseClass constructor
};
class DerivedClass1 : public BaseClass {
public:
DerivedClass1(int a, double b, int c) : BaseClass(a, b, c, d) {};
std::string d = "Hello";
};
class DerivedClass2 : public BaseClass {
public:
DerivedClass2(int a, double b, int c) : BaseClass(a, b, c, d) {};
std::string d = "Goodbye";
};
< /code>
Однако я, безусловно, что -то делаю не так, так как я получаю
warning: field 'd' is uninitialized when used here [-Wuninitialized]Подробнее здесь: https://stackoverflow.com/questions/765 ... -class-con