dimanche 26 juillet 2015

should I be using the inline keyword for small getters that return std::string

I pretty much as standard use the inline keyword on all of my one line getters, as per the recommendations in numerous 'where should I use inline keyword' posts on here and other places.

And whilst this makes perfect sense to me in say the case where your function looks like this:

inline const char* getString() {return this->myString;}

I do wonder if the common wisdom should equally apply to this function:

inline std::string getString() {return this->myString;}

At first glance they look the same but when you take a closer look at it you realise that there is a WHOLE bunch of code which I can only assume the compiler is 'blowing up in place' with the std::string example.

However, being a bit of a beginner with c++, I don't really know enough about how the compiler works to know if my imagining about it simply replacing the words std::vector with loads of code is correct. So my question is this - is it really correct to use the inline keyword on one line getters if they have complex return types like std::string or std::vector?

Aucun commentaire:

Enregistrer un commentaire