#include<iostream> #include<string> #include<vector> using namespace std; string& refToeElement(vector<string>& inventory, int i); int main() { vector<string>inventory; inventory.push_back("sword"); inventory.push_back("armor"); inventory.push_back("shield"); cout << "Sending the returned reference to cout:\n"; cout << refToeElement(inventory, 0) << "\n\n"; cout << "Assigning the returned reference to another reference.\n"; string& rStr = refToeElement(inventory, 1); cout << "Sending the new reference to cout:\n"; cout << rStr << "\n\n"; cout << "Assigning the returned reference to a string object.\n"; string str = refToeElement(inventory, 2); cout << "Sending the new string object to cout:\n"; cout << str << "\n\n"; cout << "Altering an object through a returned reference.\n "; rStr = "Healing Potion"; cout << "Sending the altered object to cout:\n"; cout << inventory[1] << endl; return 0; } string& refToElement(vector<string>& vec, int i) { return vec[i]; } 

Closed due to the fact that the essence of the question is not clear to the participants Visman , gbg , iluxa1810 , Harry , aleksandr barakin 12 Nov '16 at 14:40 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    This question should be closed, since the answer to it can hardly be useful to anyone other than the author of the question. - aleksandr barakin

1 answer 1

Announcement and definition with different names ...

 string& refToeElement(vector<string>& inventory, int i); string& refToElement(vector<string>& vec, int i) 

Here the linker does not understand where to take the refToeElement .