Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!




   1058

[C++] "using" and header files

by Pshyotic - 02 April, 2020 - 04:39 PM
This post is by a banned member (Pshyotic) - Unhide
Pshyotic  
Registered
1.011
Posts
289
Threads
8 Years of service
#1
Okay, so I've been reading some things about C++ and therefore I founded sentence which says that we should AVOID using "using" in header files, now there was example of it which says: " Let's say you're creating a library of your own and giving it to other people, if you put "using" declarations in your own header files then now you're sort of polluting the names that the other people are going to see when they include your header file. " which I quiet don't understand, what does it means "polluting the names", can someone who have knowledge about this can give a more specific example, where I can see actual problem in using "using" in header files.
 
P S H Y O T I C

☻♥
[Image: Czwhvkg.png]
This post is by a banned member (GreekYogurt) - Unhide
5
Posts
0
Threads
6 Years of service
#2
Let's say I have header A and header B. Let's say your header A has some a function checkMinutes() inside namespace "Clock". My header B also has a function checkMinutes() but in a different scope, called "Physics". We have both, header A and B included in our source file. I want to access function checkMinutes() from header B many times, thus for the sake of convenience I will just write using namespace Physics. I call function and I get... an error. I have to debug, tedious and hard task... Until I find that you included using in your header A, which caused an ambiguity between the names of variables.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)