: This (...)
• One constructor can call another constructor.
Struct ColouredPoint
{
Public ColouredPoint (int x, int y)
: This (x, y, Colour. Red)
{
}
Public ColouredPoint (int x, int y, Colour c)
{
...
}
...
Private int x, y; www.2cto.com
Private Colour c;
}
There is always a public default constructor declared by the compiler. Whether you declare a constructor or not, the public default constructor declared by the compiler always exists. Therefore, you cannot define the default constructor, so two default constructor will appear, which is not allowed. However, it should be noted that this is only applicable to structures and is not applicable to classes. The default access permission of the User-Defined constructor of the structure class is private, which is the same as that of the structure class field.
C # You cannot declare a function with the same name as the constructor.
Author: ershouyage