I have a C++ class which contains in its members a std::string*. I want to make a constructor for this class, which takes a std::string as an arguement and makes the string pointer to point at it:
class foo
{
private:
std::string * bar;
public:
foo(std::string);
}
foo::foo(std::string s)
{
//code
}
If I do this->bar = &s; it obviously doesn't work (saves the address of the s string, as it should). How do I go about doing this?
I tried creating a constructor which takes a string pointer as its arguement but it also didn't work properly, I assume for similar reasons.
Edit: Upon reading the comments I decided to alter the constructor so it now takes a std::string* as its arguement, and work from there forward.