Hi Guys,
Currently I am working on a project that involves extensive use of map, list, and vector.
Following some good programming practice, I have made sure that these variables are not global. Now, obviously I do want to access these containers in pretty much all of my functions. I have read somewhere, that we should always pass containers to other functions as references, because it causes lot of overhead to copy into local variables when passed as value. Is it so?
Also, in the scenario below:
1 2 3 4 5 6 7
|
class myClass {
private:
vector<string> myVec;
public:
vector<string> getVec() ;
void setVec(string s) ;
} ;
|
Is it good idea to return private variable? I am not returning reference to them so I guess it should be all right or not ?
Last Question,
1 2
|
map<string,myClass> myMap;
void accessVector(map<string,myClass>& myM);
|
In the above code snippet, in the function
accessVector
. I want to access the
vector returned from
myClass. So in order to do that, should I pass in entire map to
accessVector or should I just pass vector to it? Actually, to keep my
main() clean, I am passing full map to the function. But I am not sure if that is a good practice.
Please guide me through.
Thanks