Sign in to follow this  

passing std:string to function taking const std::string&

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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. :)

Share this post


Link to post
Share on other sites

This topic is 3600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this