号码作品:
template <int age>
class Parent {
};
class Child : public Parent<33> {
};
但是如何传递一个字符串呢?
template <char *text>
class Parent {
};
class Child : public Parent<"ololo"> {
};
号码作品:
template <int age>
class Parent {
};
class Child : public Parent<33> {
};
但是如何传递一个字符串呢?
template <char *text>
class Parent {
};
class Child : public Parent<"ololo"> {
};
我现在将向您展示一个技巧,但不要告诉任何人 :) 因为重点完全建立在,嗯... Visual C++ 的特性上。
其中,对于一个字符串(甚至是全局的),简单地传递它是行不通的:
但是如果你这样转,如下图,那Visual C++ 2015就吞没鬼脸了:
您不能在模板中使用文字字符串,因为不清楚它是每次不同还是相同。通过这样做,您将必须创建一个变量并已经使用它: