В приведенном ниже фрагменте, Base_type_t имеет 2 аргументы шаблона; T1 и k1 . Шаблоны foo_t , bar_t и baz_t выводятся из этой базы, используя параметр полученного шаблона для t1 , но предоставление конкретного значения для k1 .
В шаблоне функции я хочу Templatedtype
. base_type_t , у которого уже есть аргумент k1 , но аргумент t1 неопределен. Разрешает ли C ++ это?template
struct base_type_t {};
template
struct foo_t : public base_type_t {};
template
struct bar_t : public base_type_t {};
template
struct baz_t : public base_type_t {};
// How do I restrict `TemplatedType` to be a child of `base_type_t`,
// which has the parameter `k1` already specified?
template
void UseModel()
{
// Only the template argument `T1` of `base_type_t` is specified.
// The argument `k1` must be specified by `TemplatedType`.
TemplatedType instance1 { };
TemplatedType instance2 { };
}
int main()
{
UseModel();
UseModel();
UseModel();
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... emplated-t