【发布时间】:2016-11-04 16:09:35
【问题描述】:
我自己做这个语法,因为我认为以后更方便。
temolate<typename U> struct identity{typedef U type;};
temolate<typename T, typename identity<T>::type value=0> struct my{
typedef std::vector<T> vec;
typedef std::array<T,value> arr;
typedef std::set<T> set;
// and so forth
};
我使用它:
int main(){
my<int>::vec v; // okay
my<int,3>::arr a; // okay
// and so forth
}
但我也希望这样做:
(以上我的专精)
template<??????????> // what should I do here?
struct my<?????????>{ // or may be here
typedef int i;
typedef float f;
typedef double d;
// and so forth;
}
所以我可以这样做:
int main(){
my::i a; // for int, what should I do?
my::f b; // for float, and
my::d c; // for double, and
// AND I ALSI CAN
my<int>::vec v; // already I know
my<int,3>::arr a; // and know
}
有可能吗?
我在这里见过:
Default template parameter partial specialization
在我问之前。所以我知道my<>::i 是可能的。
而且我也知道如何使用 alias 和 using
我只是问这可能吗?与其对我说 NO,不如让我 downvote
【问题讨论】:
-
如果我理解正确的话。当然可以,但您仍然需要使用
my<>::i等。 -
究竟什么是完成投票?
-
@skypjack,谢谢。我不是英语母语,也只是学习它,我也使用我的平板电脑。