There are some classes and their relationships are as follows:
class X:A,B
class Y:A,B
class Z:A,B
I want to pass a general type that will inherit from A and B to testFunction using template. My code is as follows:
template<template T:public A, public B>
void testFunction(T generalType)
{
//do something
}
but my compiler told me that it's error template. How could I fix it?
The standard method to conditionally define a template is std::enable_if<condition>
. In this case, you want to check the condition std::is_base_of<A,T>::value && std::is_base_of<B,T>::value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With