devxlogo

Use Unnamed Namespaces to Declare Global Varables

Use Unnamed Namespaces to Declare Global Varables

To declare a variable or function at file scope (to create internal linkage), you declaring them as static, like this:

static int i; (file scope).

However, this is a deprecated way to declare global variables. Instead, use unnamed namespaces, as follows:

namespace{   int i;   void run();};

Place this directly into the source code.

devx-admin

Share the Post: