C++ typedef和templates

giv*_*ivi 2 c++ templates typedef compiler-errors

假设有一个小班

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
    }
};
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

预期';' 表达后.

编辑:我不知道为什么关于typename的答案被删除,因为它实际上有帮助.但有人可以解释为什么我要在另一个类模板中编写此代码时必须使用typename?

Pra*_*ian 5

Test<T>取决于用于实例化的类型c<T1>,因此您需要typename在定义中使用foo().

void f() {
    typename Test<int>::vetor_type tt;
}
Run Code Online (Sandbox Code Playgroud)