C++ typedef 和模板
假设有一个小类,
template<class T1>
class c {
template<class T>
class Test {
public:
typedef std::vector<T> vetor_type;
vetor_type some_var;
};
void f() {
Test<int>::vetor_type tt; //error
}
};
我收到一个错误:
预期的“;”表达后。
编辑:我不知道为什么有关类型名的答案被删除,因为它实际上有帮助。 但是有人可以解释一下,如果我在另一个类模板中编写此代码,为什么我必须使用 typename ?
Suppose there is a tiny class
template<class T1>
class c {
template<class T>
class Test {
public:
typedef std::vector<T> vetor_type;
vetor_type some_var;
};
void f() {
Test<int>::vetor_type tt; //error
}
};
I get an error:
Expected ';' after expression.
Edit: I don't know why the answer about the typename was deleted, cause it actually helped.
But could someone explain why do i have to use typename if I'm writing this code inside another class template?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Test
取决于用于实例化c
的类型,因此您需要在的定义中使用
。typename
>foo()Test<T>
is dependent on the type used to instantiatec<T1>
with so you need to usetypename
in the definition withinfoo()
...因为代码对我来说看起来不错。
可能存在拼写错误:也许vetor_type在一个地方,而vector_type在其他地方?
.. as it is that code looks good to me.
There's a possible typo: maybe vetor_type is in one place and vector_type somewhere else ?