Defining namespaced member vs free functions without qualification

前端 未结 2 2098

I sometimes declare classes in nested namespaces and when it comes to defining their member functions, I prefer not to have to qualify each one with these nested namespace name

2条回答
  •  难免孤独
    2021-01-27 10:11

    Perhaps I'm getting this wrong but if you have:

    // example.h
    namespace SomeNamespace
    {
        class SomeClass
        {
        public:
            void someMemberFunction();
        };
    
        void someFreeFunction();
    };
    

    You can also simply write:

    #include "example.h"
    
    // example.cpp
    namespace SomeNamespace
    {
        void SomeClass::someMemberFunction()
        {
        }
    
        void someFreeFunction()
        {
        }
    }
    

提交回复
热议问题