I have a function inside a class that returns a reference to a member variable.
std::vector<uint8> & getBuffer() const { return m_myBuffer; }
Now say in another class I call this method:
int someFunction() { std::vector<uint8> myFileBuffer = myFile.getBuffer(); }
This line calls the copy constructor of vector and makes me a local buffer. I do not want this, how can I instead set myFileBuffer to reference the myFile.getBuffer().
I know I can do this via pointers but wanted to use references if it is possible.
Thanks.
Note since your member method is const you should be returning a const reference.
So to use the returned value by reference do this: