as per C++11 rule 6 things (default constructor, copy constructor, move constructor, copy assignment, move assignment and destructor ) are created by default. By 2nd rule, when any custom copy, move or destructor is identified then those default operations space not generated. But in my password that complies with that is not the case. Yet this code stops working to compile v an error

call to implicitly deleted copy constructor the "Uni"When I create my own copy constructor for Uni everything works fine. (It is commented in the code, provided for reference )

Any thoughts lot appreciated.

You are watching: Call to implicitly-deleted copy constructor

Finally , ns am to run this on Mac, Xcode v LLVM compiler.

many thanks...

#include course A{public: A(int i) :numi std::clogvalue() up;;int main(int argc, const char * argv<>) Uni onenew A10; Uni twoone; //default copy ctor is implicitly deleted. Why ?
c++ c++11 default-copy-constructor
re-publishing
boost this question
follow
edited Feb 21 "17 in ~ 13:08

*

ruipacheco
12.6k1515 yellow badges6969 silver- badges124124 bronze title
inquiry Oct 24 "13 in ~ 7:23
*

cpp_hexcpp_hex
54711 gold badge44 silver- badges66 bronze badges
1
include a comment |

1 answer 1


active oldest Votes
51
C++11 rule for automatically generation of special members aren"t as an easy as you post them. The most important difference is that in part cases, the member is implicitly declared, but defined together deleted. That"s what happens in her case.

C++11, §11:

A defaulted copy/move constructor because that a course X is characterized as turned off (8.4.3) if X has:

a different member v a non-trivial equivalent constructor and X is a union-like class, a non-static data member of class form M (or array thereof) the cannot it is in copied/moved since overload resolution (13.3), as used to M"s corresponding constructor, results in an pass out or a duty that is turned off or inaccessible from the defaulted constructor, a straight or online base course B the cannot be copied/moved due to the fact that overload resolution (13.3), as used to B"s corresponding constructor, outcomes in an faint or a duty that is deleted or inaccessible indigenous the defaulted constructor, any kind of direct or online base class or non-static data member of a type with a destructor that is turned off or inaccessible from the defaulted constructor, because that the copy constructor, a non-static data member the rvalue reference type, or for the relocate constructor, a non-static data member or straight or digital base class with a form that walk not have a move constructor and also is not trivially copyable.

(Emphasis mine)

More generally, the rules because that auto-generated course members are:

If the class has no user-provided constructors, a default constructor is declared.

If the class doesn"t have a user-provided copy constructor, one is declared.

If the course has nobody of user-provided copy or move constructor, user-provided copy or move assignment operator, user-provided destructor , a relocate constructor will be claimed (but watch (*) below).

If the course doesn"t have a user-provided copy assignment operator, one is declared.

If the course has none of user-provided copy or move constructor, user-provided copy or relocate assignment operator, user-provided destructor , a move assignment operator will be claimed (but view (*) below).

If the class doesn"t have a user-provided destructor, one is declared.

Any automatically declared member deserve to be defined as defaulted (doing the default stuff) or characterized as turned off (if you shot to use it, you acquire an error). The preeminence of thumb is "If the defaulted version makes sense, it will be characterized as defaulted. Otherwise, it will be defined as deleted."

In this context, "makes sense" method "doesn"t try to contact a deleted, ambiguous, inaccessible or otherwise illegal function." because that example, the standard bit I quoted in the first part of this answer lists what doesn"t "make sense" for copy constructors.

Additionally, an instantly declared copy constructor or copy assignment operator is characterized as deleted if the course has a user-provided relocate constructor or relocate assignment operator.

See more: Yu Gi Oh Gx Duel Academy Best Deck S, Gx Duel Academy (2006) Deck

(*) If an immediately declared relocate constructor or move assignment operator would be identified as deleted, it is rather not declared at all. This preeminence exists so the trying to relocate such a course implicitly falls back to copy it instead of generating one error.