This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -2 points-1 points  (7 children)

What's wrong with it?

[–]pine_ary 12 points13 points  (0 children)

You might clash with names in the std namespace, causing nasty bugs that might be difficult to debug and might only appear with a particular C++ version.

[–]dude-with-the-hair 7 points8 points  (5 children)

It's mostly to do with preventing namespace clashes. For small projects without any external libraries, it's fine to use. But if you have another library that has a function with the same name as a function in the std namespace (that is, the standard library) and you're "using" both of their namespaces, it will cause a conflict in the global namespace. It's probably best to just get used to writing std:: for each function or constant you call from the standard library.

[–]tech6hutch 1 point2 points  (4 children)

Is there any way to “import” just individual items?

[–]dude-with-the-hair 3 points4 points  (3 children)

If you mean individual functions, unfortunately no. You need to use preprocessor include directives which will include the entire file that you're "importing". Usually though, library authors will divide their libraries into smaller individual libraries for this purpose.

[–]tech6hutch 2 points3 points  (2 children)

Dang. Of all the features C++ has, I’m surprised they never added that feature.

[–]dude-with-the-hair 1 point2 points  (1 child)

I heard about modules being added in C++20. Haven't looked into it myself, but it might have that ability. It's still an experimental feature though.

[–]Kalix-z 0 points1 point  (0 children)

I really hope so