function return value string differs from return value BOOL------C + + programming principle and practice (Advanced article)

Source: Internet
Author: User

Why are FIND_FROM_ADDR () and find_subject () so different? For example, FIND_FROM_ADDR () returns a bool value, while Find_subject () returns a string. The reason is that we want to explain:

  • FIND_FROM_ADDR () should distinguish between two different cases where the address line is empty ("") and no address lines. For the first case, FIND_FROM_ADDR () returns True (because the address row was found) and the S is set to the empty string "" (because the address is empty). For the second case, it should return False (because there is no address line).
  • For cases where the subject is empty or there are no subject lines, Find_subject () returns "".

FIND_FROM_ADDR () The distinction between these two situations is meaningful and necessary. When looking for information in a data file, there are frequent nuances of this difference: have we found the domain we want to find? Is the content in this domain useful? In an actual program, FIND_FROM_ADDR () and Find_subject () should be designed in the style of the present find_from_addr () so that the user can differentiate between the differences.

(whether the content exists, whether the content is empty, when to use BOOL (the parameter is a reference, return the content), and when to return the appropriate type)

Principles and Practice of C + + programming (Advanced article)

function return value string differs from return value BOOL------C + + programming principle and practice (Advanced article)

Related Article

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.