std::vector<T>::

Hello,

is there a way to write a template like this:

1
2
3
4
5
6
7
8
9
10
11
12
template<typename T>
class MyVector {

private:
    std::vector<T> vector;

public:
    template<typename T> std::vector<T>::size_type size() {
        return vector.size();
    }

};


The code above doesn't compile.
You don't need to write template again on line 8. The one on line 1 will encompass the entire class definition.
Okay, but that doesn't solve the problem:

Warning: 'std::vector<T>::size_type' : dependent name is not a type
Error error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1
2
3
4
5
6
7
8
9
10
11
12
template<typename T>
class MyVector {

private:
    std::vector<T> vector;

public:
    // add 'typename' to clarify that the dependent name is the name of a type 
    typename std::vector<T>::size_type size() const {
        return vector.size();
    }
};
Thanks!
Topic archived. No new replies allowed.