0

I have a simple templated class with private generic vector and I wanted to expose begin and end iterators (in order to consume these outside that class in std:accumulate).

I am trying to achieve it like so:

#include <vector>

template <typename T>
class MyClass 
{
public:
    std::vector<T, std::allocator<T>>::iterator begin() { return m_data.begin(); }
    std::vector<T, std::allocator<T>>::iterator end() { return m_data.end(); }
    //...

private:
    std::vector<T> m_data;
    //...
};

But it seems that I am doing something wrong as it doesn't compiles and reports following:

C2146: syntax error : missing ';' before identifier 'begin' 
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C2146: syntax error : missing ';' before identifier 'begin' 
C4430: missing type specifier - int assumed. Note: C++ does not support default-int

That makes absolutely no sense for me, can you point me to how begin can be exposed?

Vladimirs
  • 8,232
  • 4
  • 43
  • 79
  • 1
    You have to put typename before the dependent type. More info [here](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords). – David G May 27 '14 at 14:06
  • Solution was simply **typename** std::vector::iterator begin() { return m_data.begin(); } – Vladimirs May 27 '14 at 14:29

0 Answers0