I would like to create a function template where the class T is limited to only derived classes of a special base class T_base. What is the efficient way to accomplish this? Thanks for your help!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use type traits and SFINAE
C++03 version that also works for C++11
There is the C++11 version of moving the
enable_ifinto the template parameter list, using a default argumentSadly you then cannot overload
fif the only difference of your other overload is the SFINAE string (i.e the default argument), because the default argument is not part of the signature of a function template. But the type of the template parameters themselfs are (these rules are just like for normal function parameters).