Original Post
As I was coding recently I stumbled upon the subject of explicit constructors. I was surprised to learn that you could easily fool your compiler into constructing class objects out of single parameters like this:
This can make your code tricky to understand especially if you are writing functions that accept "MyClass" objects but you instead pass in a value. Another example where this can happen is if you are using the comparison operator.
I decided to create a video tutorial on the subject (http://www.marek-kno...hp5?vmk=cpp21p1) describing when you should and shouldn't be using the explicit keyword. From now on, I'm going to be using the explicit keyword!
MyClass myClass = 123;
This can make your code tricky to understand especially if you are writing functions that accept "MyClass" objects but you instead pass in a value. Another example where this can happen is if you are using the comparison operator.
I decided to create a video tutorial on the subject (http://www.marek-kno...hp5?vmk=cpp21p1) describing when you should and shouldn't be using the explicit keyword. From now on, I'm going to be using the explicit keyword!