Practice mode C++

Why is writing using namespace std; in a header file considered bad practice?

Correct answer C. It forces every file that includes the header to import all std names, risking name clashes

Explanation

A using-directive in a header leaks into every translation unit that includes it, directly or indirectly, and cannot be undone there. This can cause ambiguities when user code defines names such as count, distance or size that also exist in std. In headers, qualify names with std:: or use specific using-declarations inside function bodies.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.