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

前端 未结 2 489
梦毁少年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:46

    Looks like copy constructor is never called . Only constructor is called . The following code may call copy constructor

    AAA a = 1;
    AAA ab = a;
    

    Not sure why G++ is compiling it .

提交回复
热议问题