KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have 2 classes and one of them has map<string, vector<string> > I want to be able to use this in other class. Here is my code: class a { map<string, vector<string> > m; public: const map<string, vector<string> > & get() { return m; } }; class b { a obj; public: void test() { map<string, vector<string> > m= obj.get(); // and then print } }; int main(int argc, char ** argv) { b bobj; bobj.test(); return 0; } Is the way I returned reference to map in class a correct? It worked,but I just want to confirm if it was done properly / I got lucky / any other comments about the code. Thank you for your help.
Tags (comma-separated)
Save Edits
Cancel