c++ namespace best practice dilemma

后端 未结 6 1988
遥遥无期
遥遥无期 2021-01-31 03:55

I\'m finding that what I\'ve considered \"best practice\" for use namespace in c++ is hurting the readability of my code, and making me question how to use them well.

My

6条回答
  •  情歌与酒
    2021-01-31 04:21

    Here's what I do.

    In :

    namespace myproject {
      namespace mylibrary
      {
        namespace impl
        {
          using namespace otherlibrary;
          using namespace boost;
          using namespace std;
          using namespace whatever::floats::your::boat;
    
          class myclass;
          class myotherclass;
        };
        using impl::myclass;
        using impl::myotherclass;
      };
    };
    

    In the source:

    #include 
    using namespace myproject::mylibrary; //clean!
    

提交回复
热议问题