Dangerous `bool` Type --- Do NOT use `bool` type where a pointer maybe pass to.

Let's see the piece of code below:

Obviously, `foo(false)` will call `foo(bool)` as excepted.

But do you know what does `foo("1234")` actually select? The answer is `foo(bool)` too! See here for detail: http://stackoverflow.com/questions/13268608/boostvariant-why-is-const-char-converted-to-bool

There is a alt way to call `foo(const string &)`, by explictly specify the type of argument to `string`.

 

The Conclusion is:

  Do NOT use `bool` type where a pointer maybe pass to.

 

 

posted @ 2013-08-04 13:00  walfud  阅读(174)  评论(0编辑  收藏  举报