I write code and mess with computers.
- 2 Posts
- 2 Comments
Joined 5 years ago
Cake day: May 11th, 2021
You are not logged in. If you use a Fediverse account that is able to follow users, you can follow this user.
Most things in the various STD libs are namespaced as to not clash with other programs.
using namespaceimports everything in a namespace into your current namespace, even for things you didn’t include.It’s just a shortcut to write less, and is a bad habit taught to beginners. It can cause name collisions for all sorts of things since it imports all of std, not just the headers you include.
Just don’t use it. If you insist, scope your use of
usingby putting it inside of functions/methods, and specify specific things to import (i.e.using std::string;).




Yeah the value copy is necessary to return the old (pre-increment) value with i++. However, your compiler is (usually) smart enough to optimize the copy away if you never use it.
That being said, being explicit is good, so use ++i if you don’t need the old value. Don’t depend on the compiler to maybe do something.