We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<iostream>usingnamespacestd;enumclassFruit{apple,orange,pear};enumclassColor{red,green,orange};template<typenameT>structTraits;// Define specializations for the Traits class template here.template<>structTraits<Color>{staticstringname(intindex){switch(static_cast<Color>(index)){caseColor::red:return"red";caseColor::green:return"green";caseColor::orange:return"orange";default:return"unknown";}}};template<>structTraits<Fruit>{staticstringname(intindex){switch(static_cast<Fruit>(index)){caseFruit::apple:return"apple";caseFruit::orange:return"orange";caseFruit::pear:return"pear";default:return"unknown";}}};intmain(){intt=0;std::cin>>t;for(inti=0;i!=t;++i){intindex1;std::cin>>index1;intindex2;std::cin>>index2;cout<<Traits<Color>::name(index1)<<" ";cout<<Traits<Fruit>::name(index2)<<"\n";}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Template Specialization
You are viewing a single comment's thread. Return to all comments →
i thing it like that rule