http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56889

--- Comment #4 from Amali Praveena <amalisperid at yahoo dot com> 2013-04-09 
19:02:32 UTC ---
Hi Jonathan,
     The Stack in the example is an abstract type, so I'm explicitly saying
that this abstract type cannot be copied or moved; but the derived class
vector_stack, which provides implementation for this abstract type is copyable
through clone function. Since the compiler won't know to which more derived
class the Stack points to at run time and so it cannot copy it, I've provided
the clone function (clone pattern).

This is what bjarne stroustrup says in his draft version of PL Fourth Edition,
as I quoted before.
Here is that section from the book.
3.3.4 Prev enting Copy and Move [tour2.copy.hier]
Using the default copy or move for a class in a hierarchy is typically a
disaster: Given only
a pointer to a base, we simply don’t know what members the derived class has
(§3.3.3), so
we can’t know how to copy them. So, the best thing to do is usually to delete
the default
copy and move operations; that is, to eliminate to default definitions of those
two operations:
class Shape {
public:
Sha pe(const Sha pe&) =delete; // no copy operations
Sha pe& opera tor=(const Sha pe&) =delete;
Sha pe(Sha pe&&) =delete; // no move operations
Sha pe& opera tor=(Shape&&) =delete;
˜Sha pe();
// ...
};
Now an attempt to copy a Sha pe will be caught by the compiler. If you need to
copy an
object in a class hierarchy, write some kind of clone function (§22.2.4).
In case you forgot to delete a copy or move operation, no harm is done. A move
operation
is not implicitly generated for a class where the user has explicitly declared
a destructor.
Furthermore, the generation of copy operations are deprecated in this case
(§42.2.3). This can be a good reason to explicitly define a destructor even
where the compiler
would have implicitly provided one (§17.2.3).
The C++ Programming Language, 4th edition ©2012 by Pearson Education, Inc.
Reproduced in draft form with the permission of the publisher. D R A F T

Thanks,
Amali.


________________________________
 From: redi at gcc dot gnu.org <gcc-bugzi...@gcc.gnu.org>
To: amalispe...@yahoo.com 
Sent: Tuesday, 9 April 2013 10:26 PM
Subject: [Bug c++/56889] =delete(ing) default copy and move operations for a
polymorphic type gives compilation error messages


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56889

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2013-04-09
12:26:18 UTC ---
As Daniel says, you're missing a default constructor.

And if you define the type as non-copyable then obviously you can't copy it.

This is not a GCC bug.

Reply via email to