C++ Challenge - Local Reference 06-29-2014, 09:30 AM
#1
Code:
#include <iostream>
std::string get_string()
{
return std::string("My String");
}
int main()
{
/* declare 'obj' as a reference to the temporary
string object returned by get_string() below...
(remember: references use &, i.e. std::string &var_name, for instance)*/
// -- CODE HERE --
std::cout << "Before: " << obj << std::endl;
obj = "Changed!";
std::cout << "Modified: " << obj << std::endl;
}Description is commented within the above code. You can't change any of the existing code, you can only add code where specified (// -- CODE HERE -- ). You must create a std:
tring object which is a reference to the local variable returned by the get_string() function, and the code must compile, containing all of the existing code. You can't modify the function get_string() at all either. 
NOTE: Because of the context of the given code, this is a C++11 challenge...
Good luck.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
