• Source
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. class person {
    6. string names, spouse, gender;
    7. public:
    8. person (string nm): names (nm) {
    9. // To demonstrate that the parent object is called before the child object.
    10. cout << "New person created. " ;
    11. }
    12.  
    13. //pure virtual function "divorce ()" makes "person" an abstact class
    14. virtual void divorce () = 0;
    15.  
    16. string getGender() {return gender;}
    17.  
    18. void resetSpouse() {spouse.clear();}
    19.  
    20. string getSpouse() {return spouse;}
    21. };
    22.  
    23. class man: public person {
    24. string manGen;
    25. public:
    26. man (string name): manGen ("Male"), person(name) {
    27. cout << "Male added." << endl;
    28. }
    29. void divorce() {resetSpouse ();}
    30. };
    31.  
    32. class trans: public person {
    33. string transGen;
    34. public:
    35. trans (string name): transGen ("Trans"), person(name) {
    36. cout << "Trans added." << endl;
    37. }
    38. void divorce() {resetSpouse ();}
    39. };
    40.  
    41. class woman: public person {
    42. string womanGen;
    43. public:
    44. woman (string name): womanGen ("Female"), person(name) {
    45. cout << "Female added." << endl;
    46. }
    47. void divorce () {resetSpouse ();}
    48.  
    49. };
    50.  
    51. int main () {
    52. woman jane ("Jane");
    53. man notJane ("Jack");
    54. trans notJack ("Unicorn");
    55. return 0;
    56. }
    57.  
    58. /*
    59. Output:
    60.  
    61. New person created. Male added.
    62. New person created. Male added.
    63. New person created. Trans added.
    64. */
    65.