There is an abstract class Human , two classes are inherited from it: Man and Woman . I create an instance, but I do not know whether it is a man or a woman.
How competently is this problem solved in practice?
At the moment it is written as follows, but it’s not done like that ...
class Human {}; class Man : public Human {}; class Woman : public Human {}; Human *createHuman(bool gender); // Возвращает указатель на созданный Man или Woman int main() { Human *firstHuman = createHuman(1); } Is this problem solved through the Human class constructor?
createHuman. - VladDManorWoman, because in general, the sizes of these types may be different. The decision that you will create must be made before the memory is allocated. - AnT