How to implement static class member functions in *.cpp file?

前端 未结 8 1466
Happy的楠姐
Happy的楠姐 2020-12-07 15:35

Is it possible to implement static class member functions in *.cpp file instead of doing it in the header file ?

Are all static functions a

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 15:46

    In your header file say foo.h

    class Foo{
        public:
            static void someFunction(params..);
        // other stuff
    }
    

    In your implementation file say foo.cpp

    #include "foo.h"
    
    void Foo::someFunction(params..){
        // Implementation of someFunction
    }
    

    Very Important

    Just make sure you don't use the static keyword in your method signature when you are implementing the static function in your implementation file.

    Good Luck

提交回复
热议问题