A Conversion Constructor is a type of [[C++]] [[Constructor]] that converts one type into a instance of the class. A Conversion constructor is any constructor that takes in a single argument of type $T$. If a constructor of type $S$ does this, it is a Conversion Constructor that converts $T \to S$. >[!example] $\text{const char}* \to \text{CString}$ >```cpp >class CString { > // ... > CString(const char* source) { > // ... > } > // ... >}; > >int main() { > // Implicit Constructor Call to convert const char* to CString > CString string = "Bruh"; > return 0; >} >``` ## Explicit vs Implicit By default, all conversion constructors are *implicit*. As a rule of thumb, unless you have a **very good** reason, you should make your conversion constructor explicit with the `explicit` keyword. >[!example] Explicit $\text{const char}* \to \text{CString}$ >```cpp >class CString { > // ... > explicit CString(const char* source) { > // ... > } > // ... >}; > >int main() { > // Implicit Constructor Call to convert const char* to CString > CString string0 = "Bruh"; // Compiler Errror > CString string3 = {""}; // Compiler Error > > CString string1 = CString{"Bruh"}; > CString string2{"Bruh"}; > return 0; >} >```