Assignment operator - Self-assignment

前端 未结 3 1011
梦如初夏
梦如初夏 2021-01-08 01:25

Does the compiler generated assignment operator guard against self assignment?

class T {

   int x;
public:
   T(int X = 0): x(X) {}
};

int main()
{
   T a(         


        
3条回答
  •  孤街浪徒
    2021-01-08 01:30

    class T {
        int x;
    public:
        T(int X = 0): x(X) {}
    // prevent copying
    private:
        T& operator=(const T&);
    };
    

提交回复
热议问题