givi
givi

Reputation: 1903

C++ typedef and templates

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?

Upvotes: 2

Views: 174

Answers (2)

Praetorian
Praetorian

Reputation: 109119

Test<T> is dependent on the type used to instantiate c<T1> with so you need to use typename in the definition within foo().

void f() {
    typename Test<int>::vetor_type tt;
}

Upvotes: 5

matiu
matiu

Reputation: 7725

.. 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 ?

Upvotes: 0

Related Questions