In copy-initialization, is the call to the copy constructor explicit or implicit?

前端 未结 2 490
梦毁少年i
梦毁少年i 2021-02-09 00:12
class AAA {
public:
    explicit AAA(const AAA&) {}
    AAA(int) {}
};


int main() {
    AAA a = 1;
    return 0;
}

In the above code, as I unders

2条回答
  •  无人共我
    2021-02-09 00:36

    Looks like this bug: g++ fails to call explicit constructors in the second step of copy initialization

    g++ fails to compile the following code

    struct X
    {
        X(int) {}
        explicit X(X const &) {}
    };
    
    int main()
    {
        X x = 1; // error: no matching function for call to 'X::X(X)'
    }
    

    The second step of a copy initialization (see 8.5/16/6/2) is a direct-initialization where explicit constructors shall be considered as candidate functions.

提交回复
热议问题