0

I am reading C++ Primer and this piece of code confuses me a little. Maybe i have read before but forgotten what its about.

this code has 2 copy constructors but i dont know what the difference is between them

class Quote {
public:
    Quote() = default;
    Quote(const Quote&) = default;    // <<== this one
    Quote(Quote&&) = default;         // <<== and this one
    Quote& operator=(const Quote&) = default;
    Quote& operator=(Quote&&) = default;
    virtual ~Quote() = default;
}

what is the difference in general?

and what do the double "&" mean?

CantThinkOfAnything
  • 1,129
  • 1
  • 15
  • 40

1 Answers1

4

They are not both copy constructors, only the first one: Quote(const Quote&) = default;. The second one is a move constructor, do some reading on move semantics and C++11.

Ionut
  • 6,436
  • 1
  • 17
  • 17
  • 1
    ``Quote(const Quote&) = default;`` is the copy constructor. ``Quote& operator=(const Quote&) = default`` is the assignment operator. ``Quote(Quote&&) = default`` is the move constructor. ``Quote& operator=(Quote&&) = default`` is the move operator. – Chuck Walbourn Apr 01 '15 at 07:17
  • hmmm i see... although in the piece of code it states "// memberwise copy" So thats what confused me. But i got it now,, thnx – CantThinkOfAnything Apr 01 '15 at 07:25