C + + stipulates that an implicit invocation is defined for a default constructor that may only pass one parameter.
Note: Simply passing a parameter refers not only to the default constructor for only one parameter, but also to those that contain the default constructor that defines the default value of the parameter.
To illustrate:
Class MyClass
{
Public
MyClass ();
MyClass (string s);
MyClass (int i, int y = 0);
}
Here the MyClass (string s) function and the MyClass (int i, int y = 0) function are the default constructors that may only be passed one parameter
Look at the case where the class object is constructed using constructors:
- MyClass Obj1;//ok, called the MyClass ()
- MyClass obj2 (String ("Hello world!")); /ok, called MyClass (string s)
- MyClass obj3 (0),//ok, called MyClass (int i, int.
- MyClass Obj4 (12);//Ibid.
- MyClass obj5 = 12;//Ibid. But for Obj5, it is actually equivalent to MyClass temp (12); MyClass obj5 (temp);//means that the default copy constructor is called by default. This is known as implicit invocation.
In most cases, implicit invocation can cause bugs and is difficult to detect. Based on this, C + + introduces the Explict keyword to turn off this implicit invocation and avoid the bug caused by an implicit invocation.
Explict keywords in C + +