我所尋找的是一種方法,即說。這對所有的專業都是一樣的:
我正在尋找一種方法來說明:所有的專業都是一樣的。
template <typename T>
結構 Foo {
using id_type = unsigned int; // this does not depend on T!
};
Foo::id_type theId; //不管專業化是什么,id_type總是一樣的。
我想訪問id_type而不需要指定專業化...
uj5u.com熱心網友回復:
你不可能完全擁有你所要求的東西。Foo不是一個類。Foo<T>是一個類,對于任何T。
你可以有一個持有id_type的非模板基數,
struct FooBase {
using id_type = unsigned int;
};
template <typename T>
struct Foo : FooBase{};
FooBase::id_type theId。
你可以為T
template <typename T = struct FooPlaceholder>
struct Foo {
using id_type = unsigned int; // this does not depend on T!
};
Foo<>::id_type theId。
然而,沒有什么能阻止我寫一個明確的Foo的特殊化,它缺乏(或重新定義)id_type。
template <> struct Foo< MyType> { };
template <> struct Foo< MyOtherType> { int id_type = 42; };
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/332990.html
標籤:
上一篇:WXPython事件處理-按鈕
