Class copy member

Studying the concept of "copying members", the book gives the following statement.

In addition, a default assignment cannot be generated if the non-static member is a reference, constant, or user type without a copy assignment.

I do not quite understand what this operator really wants to execute? Or what type of scenario applies to this statement? Thank.

+3
source share
4 answers

, , (.. ). , . , :

1) ( , )

class Foop {
    int& reference;
};

2) -

class Foople {
    const int someConst;
};

3) - -, - , , ( copy-constructors)

class Uncopyable {
private:
    Uncopyable(Uncopyable const& other);
};

class Fleep {
    Uncopyable uncopyable;
};

(, , ).

+2

, ( ),

  • ( )
  • ( , , )

= , .

+2
class ClassA
{
    int& _myReferenceMember;
    const int _myConstant;
    ClassB _objWhereClassBHasNoCopyConstructor;
}

. , , ( ) -.

0

:

class A { int a; };

class B { int& a; };

A (=), B . , ++ . , , , . ( ) , ( ).

A :

class A
{
   A& operator=(A const& a_) { a = a_.a; }
   int a;
};
0

All Articles