Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Preserve Code Safety with Conversion Operators

Inadvertent object conversion can seriously jeopardize your code's safety. Luckily, conversion operators allow you to enable or disable conversions as you wish, helping you avoid those that are ill-behaved.




Application Security Testing: An Integral Part of DevOps

ertain objects must be converted to a low-level representation and vice versa. Programmers using std::string objects, for instance, have to convert them to bare char pointers, as in the following example:

string inf="mydata.txt"; ifstream infile(inf.c_str());//const char* required

Similarly, POSIX programmers need to convert <fstream> objects to file descriptors to use native system calls.

How to automate conversions of objects to their underlying types without compromising code safety?

Use conversion operators and explicit constructors to create objects with a dual-interface while avoiding ill-behaved conversions.

Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date