passing std:string to function taking const std::string&
Okay, im really sorry for posting this, because im sure this is a trivial thing, but i cant for the love of me figure out how to pass an element from array of std::string to a function taking const std::string& , nor can i find any resources on the matter. So without further ado, what is the correct way to do this?
If the function takes const std::string&, you pass it exactly the same way as if it took std::string (by value). The only difference is semantic: the passed string will *be* the one from your array, instead of being a copy.
If your problem is obtaining an element of an array of std::string, it's exactly the same as accessing an element of an array of int.
In short, the simplest possible thing you could think of is correct. :)
If your problem is obtaining an element of an array of std::string, it's exactly the same as accessing an element of an array of int.
In short, the simplest possible thing you could think of is correct. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement