I have a class like this one:
class Test{
public:
Test(string value);
Test(bool value);
};
If I create an object like this:
When you have a constructor (especially multiple constructors) that take only a single argument, it may be suitable to declare them "explicit" to avoid these kind of surprises. This forces the user of the class to make sure he gives the correct type to the constructor he wishes to use and prevents these implicit type conversions from being done behind the users back and hiding hard to find bugs.
http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=15&rll=1
In C++0x, this has been extended to conversion operators to prevent the same issue
http://www2.research.att.com/~bs/C++0xFAQ.html#explicit-convertion