devxlogo

Correctly Defining a Function in an Unnamed Namespace

Correctly Defining a Function in an Unnamed Namespace

The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative. Nonetheless, it is important to know how to define the members of an unnamed namespace correctly. Declaring a function in an unnamed namespace and defining it later, somewhere outside that unnamed namespace, is a common mistake:

 namespace {  void func(); //only a declaration}void func() //most likely an error{  //

devx-admin

Share the Post: