[英]template template class specialization
我只是在學習模板模板類專業化。 不是大問題,詳細解釋一下。 根據我的理解, std::uniform_int_distribution
是一個模板,而std::uniform_int_distribution<Type>
是給出類型的uniform_int_distribution
的完全特化。 我在專業化類模板中傳遞了這個,如下所示
主班
template <template <class> class Distribution,
class Type,
class Engine = std::mt19937>
class random_gen
{
....
}
班級專業化
template <class Type, class Engine>
class random_gen<std::uniform_real_distribution<Type>, Type, Engine>
{
...
}
發生的錯誤是:
type/value mismatch at argument 1 in template parameter list for 'template<template<class> class Distribution, class Type, class Engine> class random_gen'
專業化仍然需要是一個模板模板參數。 你傳入了一個完整的類型。 你要:
template <class Type, class Engine>
class random_gen<std::uniform_real_distribution, Type, Engine>
{
...
};
只是std::uniform_real_distribution
,而不是std::uniform_distribution<Type>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.