65,211
社区成员
发帖
与我相关
我的任务
分享template<char* str>
struct some_template
{
static const char* get_value() { return str; };
};
void foo()
{
cout << some_template<"abcd">::get_value() << endl;
}
typename enum {
apple,
orange
} fruit;
template <typename fruit f>
struct get_fruit_string;
template <>
struct get_fruit_string<orange> {
static string get_string() {
return "orange";
}
}
template <>
struct get_fruit_string<apple> {
static string get_string() {
return "apple";
}
}
// 调用方法:
cout << get_fruit_string<apple>::get_string() << endl;
struct apple{}
struct orange{}
template <typename T>
struct get_fruit_string;
template <>
struct get_fruit_string<apple> {
static string get_string() {
return "apple";
}
}
template <>
struct get_fruit_string<orange> {
static string get_string() {
return "orange";
}
}
// 调用方法:
cout << get_fruit_string<apple>::get_string() << endl;
template<int *> void f();
static int a;
extern int b;
int main()
{
f<&a>(); //fail
f<&b>(); //OK
}