code_junkie

C++ How can I get a return a reference and save the refence as a local variable in a function?

Nov 13th, 2011
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. std::vector<uint8> & getBuffer() const
  2. {
  3. return m_myBuffer;
  4. }
  5.  
  6. int someFunction()
  7. {
  8. std::vector<uint8> myFileBuffer = myFile.getBuffer();
  9. }
  10.  
  11. // Note the extra const on this line.
  12. std::vector<uint8> const& getBuffer() const
  13. {
  14. return m_myBuffer;
  15. }
  16.  
  17. std::vector<uint8> const& myFileBuffer = myFile.getBuffer();
  18.  
  19. std::vector<uint8>& myFileBuffer = myFile.getBuffer();
  20.  
  21. std::vector<uint8> myFileBuffer = myFile.getBuffer();
Add Comment
Please, Sign In to add comment