Class myclass001
{
PRIVATE:
Public:
Myclass001 ()
{
Printf ("myclass001 ");
}
Myclass001 (int I)
{
Printf ("MyClass001-i ");
}
};
Resolve:
Myclass001 K1; // display myclass001
K1 = 1; // display MyClass001-i
In fact, the second sentence is equivalent to calling the constructor with int I. In fact, it is assigning an I value to the constructor.
Thus, myclass001 (int I) is called ).
If you write a class test;
Class Test
{
Public int I;
}; Before myclass001.
Then change myclass001 (int I)
{
Printf ("MyClass001-i ");
}
Myclass001 (test * TT)
{
Printf ("MyClass001-test ");
}
Statement
Myclass001 K1;
K1 = new test;
Correct. It is obvious that new test is passed in as a parameter.
The parameter is not initialized when the object is declared, so the constructor without parameters is called to construct the object.
The value of the second row does not match the type on both sides of the equal sign. Therefore, the compiler does not find any constructor that uses the data type on the right as the parameter. After finding the constructor, a temporary object is constructed and then assigned a value.