Jump to content
  • Advertisement
Sign in to follow this  
KaelisAsur

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

This topic is 3965 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
Advertisement
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
Thank you! The issue turned out to be elsewhere (and a trivial one at that), but your responses assured me that im doing everything right and helped me find it =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!