m_Why?

Pages: 12
It is also essential to use fully qualified scope names when declaring friends, even though friends are often shunned in C++. They're helpful for nested classes & PIMPL though, which is how I found out.
Interesting how you conveniently missed out #1, "My code will never be in the std namespace". An honest mistake, I'm sure, but it makes your (contrived) example totally irrelevant. I also don't write using namespace and I don't name identifiers the same thing as ones in the standard library (except possibly by accident) so even if I did put code in a namespace called std, your example still wouldn't be problematic. So my rules still stand up.
Last edited on
Interesting how you conveniently missed out #1
#1 may be subject to change
if I were to revise it, I would remove the word "never"
My code will never be in the std namespaceMy code will be in the std namespace :P
Also technically code isn't in std:: namespace, it is in myCoolNamespace::std::

I was worried about something like
1
2
3
using namespace std;
#include "someheader" //Can be there ambiguity in some calls like dstance(x. y)?
                      //Which be pointed as errors in header itself 

But name lookup rules doesn't let it happens. So point 3 still stays unchallenged in regard of not using ::std::.
However I still think that using directive is useful if you:
a) Place it not in global block.
b) Use it like using std::chrono::high_resolution_clock::time_point (some standard definitions is quite long...)
Last edited on
My code will never be in the std namespace → My code will be in the std namespace :P
Also technically code isn't in std:: namespace, it is in myCoolNamespace::std::

Okay, you've got me there (on a technicality (well, two, actually)). Let me revise my first rule to
1. My code will never inappropriately be in a namespace called std
where "inappropriately" means "when not implementing the standard library (or a subset thereof)".
Last edited on
Topic archived. No new replies allowed.
Pages: 12