What is the syntax for returning a reference to a vector from a function? I have a private vector and I want to return it using a public get function (like in the code below), but I believe that what I have will make a copy of the vector, and my real vector is several hundred bytes. Do I have to cast it as a constant? What is the syntax for that (or where does one look)?
Sorry if these are basic questions - alas, I've been scouring the internet for several days now!!!
Many thanks for any assistance you can offer!
Michele
Expand|Select|Wrap|Line Numbers
- #include <string>
- #include <vector>
- #include "VectorThing.h"
- using namespace std;
- VectorThing::VectorThing()
- {
- vect.push_back("macaroni");
- vect.push_back("cheese");
- }
- vector <string> VectorThing::getVector()
- {
- return vect;
- }
- And this is my header file:
- #include <string>
- #include <vector>
- using namespace std;
- class VectorThing
- {
- public:
- VectorThing();
- vector <string> getVector();
- private:
- vector <string> vect;
- };