function returning reference to a vector element

Viewed 10506

I cannot figure out how to return a reference to a vector element. The [] and at() are returning reference, no?

But when I try the following, it won't compile.

I'm using Visual C++ and it gives cannot convert from 'const float' to 'float & error.

T& GetElement(size_t x) const {
    return _vector.at(x);
}

GetElement is a method, and _vector is a member variable.

2 Answers
Related