为了说清楚,我想模仿 std::vector
的 value_type
成员的行为。
例如:
template <class T>
class foo{
//some declaration and definition for value_type
};
int main(){
foo<int> bar;
bar::value_type x=5; //x is int
}
我该如何实现?
最佳答案
尝试:
template <class T>
class foo {
public:
typedef T value_type;
};
顺便说一句:bar::value_type
无效,您应该将其用作:
foo<int>::value_type x = 5; //x is int
关于c++ - 在类外知道模板的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34918112/