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?