Constructor that defines the implicit conversion from string type to type
of your class
Can someone explain in plain terms what implicit conversion from string type to type of your class means?
Constructor that defines the implicit conversion from string type to type
of your class
Can someone explain in plain terms what implicit conversion from string type to type of your class means?
A conversion constructor is basically a constructor that take a single argument of one type (different from the class), and uses it to initialize the object.
Lets say you have the following class:
struct Foo
{
Foo() = default; // Defaulted default constructor
// Conversion constructor, allows construction from int values
Foo(int)
{
}
};
Then you can create Foo object with an int value:
Foo f = 1; // Equivalent to Foo f = Foo(1)
It also allows assignments from int values:
f = 2; // Equivalent to f = Foo(2)