vendredi 8 janvier 2021

Returning member object with copy ctor (e.g. std string) from a method by value in C++11 - will it be moved? [duplicate]

class foo
{
    std::string m_str;

public:
    std::string GetString() const
    {
        return m_str;
    }

    // ...
};

In C++11 GetString() will return a copy of m_str, just like it is in C++98, or m_str will be moved? It's more general question for all objects that has move constructor, not only for std string. Any links for futher reading on the topic are very appreciated.

Aucun commentaire:

Enregistrer un commentaire