You don't need anything like this for C++
You don't need anything like this for C++
Posted Jul 5, 2012 22:20 UTC (Thu) by cmccabe (guest, #60281)In reply to: You don't need anything like this for C++ by jwakely
Parent article: Calling for a new openSUSE development model
> Are you sure?
Well, let's try it.
#include <stdint.h>
#include <stdio.h>
namespace version1 {
void foo(int64_t a) {
printf("version1 foo\n");
}
}
inline namespace version2 {
void foo(float b) {
printf("version2 foo\n");
}
using namespace version1;
}
int main(void) {
foo(0x123);
return 0;
}
gcc 4.6.2 gives me "foo.cpp:22:14: error: call of overloaded ‘foo(int)’ is ambiguous". So it's not as bad as I thought-- just a compile-time failure, not silently doing the wrong thing.
[snip example]
Yes, you could add an explicit "using" line for each version1 symbol, to avoid this problem.
This all seems very similar to just adding a "using namespace version2" to your header file. I guess some people are worried about the potential for conflicts with whatever is already in your namespace, though.
Overall it I give it a "meh." It's not that useful, but it's not seriously harmful either. Which means it's doing better than a lot of language extensions. On the other hand, I do think the copy constructor stuff will be useful (so you see, I'm not just a complete curmudgeon) :)
