0

I am trying to write a class that has a vector member. I want to make certain methods of this vector (not all) available like this:

#include <vector>

template <class T>
class Test
{
private:
    std::vector<T> myVec;

public:
    std::vector<T>::const_reference back() const
    {
        return dataVector.back();
    }
};

int main()
{
    Test<float> myTest();
}

However, I get these errors:

test.cpp(15): error C2061: syntax error: identifier 'const_reference'

test.cpp(16): error C2334: unexpected token(s) preceding '{'; skipping apparent function body

and a warning:

test.cpp(15): warning C4346: 'const_reference': dependent name is not a type

Which I do not understand.

Questions

  • What is the issue the errors and warnings are complaining about?
  • How can I expose this vector function correctly?
Community
  • 1
  • 1
NOhs
  • 2,780
  • 3
  • 25
  • 59
  • 5
    [Where and why do I have to put the “template” and “typename” keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – songyuanyao May 20 '16 at 15:42
  • 1
    VisualStudio, gcc, clang - all give a hint that typename is missing – marcinj May 20 '16 at 15:48

0 Answers0