Unnamed Namespaces Versus Static/Local Functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This question has been asked before, but the answer was somewhat incomplete.

Isn't a function declared in an anonymous namespace supposed to be
able to be defined later in the same translation unit?  It works for
variables; For example:

// file 1 // errors
#include <iostream>
namespace {
  void foo();
  int zip;
}
void  foo() {}
int main() {
  //foo();  // this statement  generates an error
  zip = 3; // this doesn't
  cout << "zip = " << zip << "\n";
}

// error message (g++-4.5.0):
nspace.cc: In function ‘int main()’:
nspace.cc:15:7: error: call of overloaded ‘foo()’ is ambiguous
nspace.cc:10:6: note: candidates are: void foo()
nspace.cc:6:8: note:                 void<unnamed>::foo()

If the standard says one can't do that, then isn't the standard
incomplete in its use of unnamed namespaces?  How many folks will
change from using static in that case?  Or is there another
work-around other than using a unique namespace name?

Thanks,

-Tom

Thomas M. Browder, Jr.
Niceville, Florida
USA


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux