advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
The technique presented here addresses the specific case of Boolean conversions. Recently, the C++ standards committee accepted a proposal to add explicit conversion operators to C++. Do you believe that this proposal is the right solution to the problem? What about conditional declarations? Let us know in the DevX C++ Forum.
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 5/5 | Rate this item | 4 users have rated this item.
 

Restrain Conversion Operators with the "Indirect Conversion" Idiom

Have you given up implicit conversions to bool because of the bugs they cause? Find out how the "indirect conversion" idiom can help you thwart undesirable conversions while still permitting well-behaved conversions. 


advertisement
onversion operators are a dilemma. While they certainly make the usage of certain objects convenient and intuitive, they also compromise type safety, ultimately leading to unexpected runtime behavior. The following sections present a technique that significantly reduces the potential hazards of implicit conversions to bool. This technique is now becoming a de-facto standard in C++ libraries, like Boost.


You want to add a conversion operator to your class, but you're concerned about the perils of implicit conversions.


Use the "indirect conversion" idiom to thwart undesirable conversions while still permitting well-behaved conversions.

  Next Page: Presenting the Problem
Page 1: IntroductionPage 3: booling Around
Page 2: Presenting the ProblemPage 4: Smooth Operator
Please rate this item (5=best)
 1  2  3  4  5
advertisement