1

I have to write specialised classes based on a preset enum. One option is two write a definition for each member in the enum, but some of them have the same definitions, is there a way I can make two inputs in the templates behave the same

  class Test {
    public:
      Test() {
        cout << "General template object \n";
      }
  };

template < >
  class Test < int >,<char> {
    public: Test() {
      cout << "Specialized template object\n";
    }
  };

Like here, I want int and char to have the same class.

  • Send a code that actually works. Your code should compile successfully. – Ho1 Nov 21 '21 at 07:45
  • 2
    @Ho1 Not all questions need a minimum reproducible example, this one seems answerable as it is. – MatG Nov 21 '21 at 08:03
  • @MatG Sure, but a code snippet with syntactical errors is bad, and I can not suggest edits now. SO says: "Suggested edit queue is full". – Ho1 Nov 21 '21 at 08:20
  • 1
    Syntactical errors exist here as a method of conveying an unknown concept - one that may or may not have a legitimate syntax available to express that concept. – Alex Nov 21 '21 at 08:29
  • `if constexpr` makes this kind of thing much easier – Alan Birtles Nov 21 '21 at 08:33

0 Answers0