c++ - The case when the copy-constructor implicitly defined as deleted -
the section n3797::12.8/11 [class.copy]
says:
an implicitly-declared copy/move constructor inline public member of class. defaulted copy/ move constructor class x defined deleted (8.4.3) if x has:
[...]
— non-static data member of class type m (or array thereof) cannot copied/moved because overload resolution (13.3), applied m’s corresponding constructor, results in ambiguity or function deleted or inaccessible defaulted constructor
the first case ambiguity of corresponding copy/move constructor quite clear. can write following:
#include <iostream> using namespace std; struct { a(){ } a(volatile a&){ } a(const a&, int = 6){ } }; struct u { u(){ }; a; }; u u; u t = u; int main(){ }
to reflect that. or function deleted or inaccessible defaulted constructor? what's got function inaccessible default constructor? provide example reflecting that?
simply put:
struct m { m(m const&) =delete; }; struct x { x(x const&) =default; m m; }; // x(x const&) deleted!
implicitly-declared functions considered "defaulted" ([dcl.fct.def.default] / 5); more familiar pre-c++11 example might like:
struct m { protected: m(m const&); }; struct x { m m; }; // x's implicit copy constructor deleted!
note if explicitly default function after has been declared, program ill-formed if function implicitly deleted ([dcl.fct.def.default] / 5):
struct m { m(m const&) =delete; }; struct x { x(x const&); m m; }; x::x(x const&) =default; // not allowed.
Comments
Post a Comment