Search code examples
c++classsubclasstype-parameter

Subclassing a type with a type parameter and replacing the type parameter with a static type in new class


Say we have classes

class Cheese {
    string name;
};
class Wine {
    string name;
};
class Pairing: public pair {

};

How do we modify class Pairing so that T1 is always Cheese and T2 is always Wine, so that you cannot pass a type parameter to Pairing?


Solution

  • class Cheese {
        string name;
    };
    class Wine {
        string name;
    };
    class Pairing: public pair<Cheese,Wine> {
    
    };
    

    And you might want to consider this also:

    typedef pair<Cheese,Wine> Pairing;