Skip to main content
13 votes
1 answer
549 views

I have recently come across this answer about forward declaration of the class in the unnamed namespace, and I was surprised that it indeed compiles and seems to work with Clang. I thought that every ...
pptaszni's user avatar
  • 9,307
0 votes
0 answers
55 views

The following "named namespace within unnamed namespace" scenario is allowed (as I understand it): namespace foo { namespace { namespace bar { int baz() { return 42; }...
Dirk Herrmann's user avatar
0 votes
1 answer
49 views

I have the following code from a textbook: namespace sally { void message( ) { std::cout << "Hello from Sally.\n"; } } namespace { void message( ) { std::...
dvk512's user avatar
  • 59
6 votes
1 answer
197 views

I have this: #include <iostream> using namespace std; // Variable created inside namespace namespace first { int val = 500; } namespace { int val = 400; } // Global variable //int val ...
Johnz's user avatar
  • 75
0 votes
1 answer
87 views

I have the next experimental code. That code fail with segmentation fault on the labeled line. If I take out the str2MxfKey function from anonymous namespace or give a some name to namespace, code ...
Валентин Никин's user avatar
0 votes
0 answers
497 views

When implementing a function in CPP, I am used to put my helper functions in an anonymous namespace, so they don't pollute the global namespace outside the CPP file where they are defined. However, ...
antonio's user avatar
  • 483
6 votes
1 answer
163 views

I've been using a dirty trick where I use unnamed namespaces to specify different behavior for each file (it is for unit-testing). It feels like it shouldn't be well-defined, but it works on every ...
Hedede's user avatar
  • 1,173
-1 votes
1 answer
92 views

I want to update some C legacy code to C++. Suppose I had something similar to this code in C: //my_struct.h typedef struct myStruct { //some members go here } myStruct; int f1(myStruct*); void f2(...
vmp's user avatar
  • 2,460
1 vote
0 answers
317 views

I have a class template that looks like this: foo.h template<class C> class Foo { public: void memberFunc(); }; #include "foo.tpp" foo.tpp void Foo::memberFunc() { ... } ...
JensB's user avatar
  • 959
1 vote
1 answer
776 views

As answered in this question, I learnt that the static keyword to the function means it can only be seen from the functions in that file. I think unnamed namespace can be used for the same purpose. ...
HiroIshida's user avatar
  • 1,603
7 votes
1 answer
576 views

C++20 introduced modules. Any symbol that is not exported in a module has module-internal linkage. While unnamed namespaces provide a mechanism to make definitions inside an unnamed namespace have ...
John Z. Li's user avatar
  • 2,035
0 votes
0 answers
251 views

I have a redefinition problem with two functions in two different unnamed namespaces, which each is placed in two separate files. The first function grouping is in a one file: namespace { bool ...
swittuth's user avatar
1 vote
1 answer
829 views

I'm having an issue understanding compiler's complaint: namespace { } inline namespace { } gcc says inline namespace must be specified at initial definition and MSVC says what's in the title. My ...
v.oddou's user avatar
  • 6,867
4 votes
1 answer
1k views

I encountered an unusual pair of compiler warnings that seem mutually contradictory. Here's the code I've written: #include <functional> #include <iostream> namespace { std::function&...
templatetypedef's user avatar
1 vote
0 answers
46 views

When it comes to using namespaces it is really good thing to avoid name clashes. But the thing that matters me: Using anonymous namespaces. Here in my example for some reason I defined two un-named ...
WonFeiHong's user avatar

15 30 50 per page