Below is the constructor of a struct
named Complex with two member variables, Real and Imaginary:
public Complex(double real, double imaginary) : this()
{
Real = real;
Imaginary = imaginary;
}
What is the use of the part after the colon in the function header?
Colon operator (":") in R is a function that generates regular sequences. It is most commonly used in for loops, to index and to create a vector with increasing or decreasing sequence. It is a binary operator i.e. it takes two arguments.
The Scope Resolution Operator in C++ Two colons (::) are used in C++ as a scope resolution operator. This operator gives you more freedom in naming your variables by letting you distinguish between variables with the same name.
The colon has the typical histological structure as the digestive tube: mucosa, submucosa, muscularis and serosa/adventitia. The mucosa is lined by simple columnar epithelium (lamina epithelialis) with long microvilli. It is covered by a layer of mucus which aids the transport of the feces.
The logical OR operator ( || ) returns the boolean value true if either or both operands is true and returns false otherwise.
You can always make a call to one constructor from within another. Say, for example:
public class mySampleClass
{
public mySampleClass(): this(10)
{
// This is the no parameter constructor method.
// First Constructor
}
public mySampleClass(int Age)
{
// This is the constructor with one parameter.
// Second Constructor
}
}
this
refers to same class, so when we say this(10)
, we actually mean execute the public mySampleClass(int Age)
method. The above way of calling the method is called initializer. We can have at the most one initializer in this way in the method.
In your case it going to call default constructor without any parameter
It's called constructor chaining - where it's in fact calling another constructor (which takes no params in this case), and then comes back and does any additional work in this constructor (in this case setting the values of Real
and Imaginary
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With