Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap