Bad practice to declare names in the standard namespace?

前端 未结 5 745
轻奢々
轻奢々 2021-01-18 02:15

I was looking through the Google C++ style guide, and came across this:

\"Do not declare anything in namespace std, not even forward declarations of standard library

5条回答
  •  独厮守ぢ
    2021-01-18 03:04

    They're saying that you shouldn't forward declare stuff from the standard library like this:

    // myheader.h
    namespace std{
    template
    void SomeStandardFunction();
    }
    
    // use std::SomeStandardFunction
    

    Instead, you should just include the header directly:

    // myheader.h
    #include 
    
    // use std::SomeStandardFunction
    

提交回复
热议问题