Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
class MyClass { public: MyClass() = default; MyClass(const MyClass& src) = default; MyClass(const string& str) : mStr(str) {} // Move assignment operator MyClass& operator=(MyClass&& rhs) noexcept { if (this == &rhs) return *this; mStr = std::move(rhs.mStr); cout << "Move operator= (mStr=" << mStr << ")" << endl; return *this; } string getString() const {return mStr;} private:

What I have tried:

C++
class MyClass
{
public:
    MyClass() = default;
    MyClass(const MyClass& src) = default;
    MyClass(const string& str) : mStr(str) {}   // Move assignment operator
    MyClass& operator=(MyClass&& rhs) noexcept
    {
        if (this == &rhs)
           return *this;
        mStr = std::move(rhs.mStr);
        cout << "Move operator= (mStr=" << mStr << ")" << endl;
        return *this;
    }
    string getString() const {return mStr;}
private:
Posted
Updated 26-Jan-19 14:29pm
v3
Comments
Richard MacCutchan 27-Jan-19 3:48am    
Please try studying the language for yourself. All the information you want can be found in the C++ reference guides.

Quote:
MyClass() = default

Is a defaulted constructor, see point (4) of Default constructors - cppreference.com[^].
 
Share this answer
 
Comments
Maciej Los 6-Feb-19 6:25am    
5ed!
CPallini 6-Feb-19 7:18am    
Thank you!
This is a C++ 11 statement for specifying e.g. a default constructor, see: https://en.wikipedia.org/wiki/C%2B%2B11#Explicitly_defaulted_and_deleted_special_member_functions
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900