error C2106: '=' : left operand must be l-value

前端 未结 4 1543
Happy的楠姐
Happy的楠姐 2020-12-20 17:48

Looking at the other questions regarding error C2106, I am still lost as to what the issue is with my code. While compiling I get the following errors:

c

4条回答
  •  Happy的楠姐
    2020-12-20 18:26

    Your function MyVector::at(unsigned) is probably not correctly declared and looks like this:

    T MyVector::at(unsigned i) { /* implementation detail */ }
    

    What you want is for it to look like this:

    T& MyVector::at(unsigned i) { /* implementation detail */ }
    

    Notice the reference parameter (&), which will return whatever element by reference and allow the expression to be used as an l-value.

    The real question is why aren't you use std::vector instead?

提交回复
热议问题