Do not get used to using namespace std

Source: Internet
Author: User

If you want to ask me what is the worst habit I found in C ++?

I have to tell you: it is the habit of using namespace STD;

Sometimes you will find that using namespace STD can save you a lot of time to avoid STD: cout; STD: CIN; STD: Endl, STD: String, etc,

I was fortunate to have discovered this secret for a while, but now I have discovered how fatal this secret is.

A few days ago, I used the simplest program to construct a read_info class and perform >>and <Operator overloading.

When I write a program, the habits are as follows:

# Include <iostream>

Using namespace STD;

Class read_info {

.......

};

When read_info.cpp calls read_info.h, the system prompts that the private member cannot be accessed.

Why am I surprised? Why can't I access my own members.

Later, we found that the most harmful tool is using namespace STD;

Of course, I have not made it clear: Why does it affect access by members?

But I must give up on this habit.

 

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.