How to resolve a name collision between a C++ namespace and a global function?

前端 未结 3 1710
情书的邮戳
情书的邮戳 2021-01-04 18:58

if I define a namespace log somewhere and make it accessible in the global scope, this will clash with double log(double) from the standard c

3条回答
  •  臣服心动
    2021-01-04 19:18

    I'd suggest:

    foo::log::Log x; // Your logging class
    ::log(0.0); // Log function
    

    Generally I wouldn't write using namespace foo; as there is no point having it in the foo namespace if you're not going to use it and it pollutes the global namespace.

    See this related question:
    How do you properly use namespaces in C++?

提交回复
热议问题