[英]template subclassing with partial specialization
考慮以下
template<typename Type, size_t Dimensions>
struct Base
{
Base(/*some args*/) { /*do something*/ }
};
template<size_t Dim>
class Derived : Base<double,Dim> {};
派生不繼承Base的構造函數,因為它表明Base是部分專業化,因此需要一些不同的構造函數。 但是,就我而言,情況並非如此。 我主要希望它在不同情況下具有不同的名稱。 我正在尋找與宏或以下宏(如果存在)不同的解決方案。
template<size_t Dim>
struct Derived
{
typedef Base<double, Dim> Type;
}
主要是因為我不喜歡使用
Derived<n>::Type
到處都是,不確定我要
typedef Derived<n>
我使用的每n個。
嘗試這個:
template<std::size_t dim>
using foo = typename derived<dim>::type;
//usage
foo<n> bar;
這利用了C ++ 11模板的using語句
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.