27 try to do less type conversion-Objective C ++ Study Notes

Source: Internet
Author: User

One of the goals of C ++ rules is to ensure that "type errors will never happen ".

Transformation damages the type system.

Old transformation style:

(T) express;

T (Express );

New Transformation:

1,
Const_cast <t> (expression ).

A single object may have more than one address, which is directed by a base class pointer and a subclass pointer.

Because we know how to design objects, the transformation may be possible on a certain platform, but not on other platforms.

Remember:

1,
If possible, try to avoid transformation, especially to avoid dynamic_casts in code that focuses on efficiency. If there is a design that requires transformation, consider an alternative solution that does not require transformation.

2,
If the transformation is necessary, try to hide it behind a function. Then the customer can call the function without putting the transformation into their own code.

3,
We would rather use C ++-style (New Transformation) than old transformation. The former is easy to identify and has a different role. That is, the new transformation target is very narrow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.