Default vs. Implicit constructor in C++

前端 未结 2 567
执笔经年
执笔经年 2020-12-04 18:44

This is very trivial, but Czech language (my native) doesn\'t distinguish between implicit and default, so I am confused by some Czech translations what is the difference be

2条回答
  •  隐瞒了意图╮
    2020-12-04 18:49

    You seem to be confusing some of the terms. A default constructor is one which takes no parameters, an implicit call is when you directly call the constructor.

    Anyway:

    1) Test t1;

    Default constructor.

    2) Test t2();

    Function declaration.

    3) Test t3 = 3;

    Copy initialization. Will call the conversion constructor, create a temporary Test from 3, and use the copy constructor to create t3.

    4) Test t4(4);

    Direct initialization. Uses the conversion constructor directly.

    5) Test t5 = Test(5);

    Copy initialization. Similar to 3).

提交回复
热议问题