Static Functions in C++

前端 未结 8 1263
野趣味
野趣味 2021-01-17 08:09

I\'ve read a few posts on here about static functions, but still am running into trouble with implementation.

I\'m writing a hardcoded example of Dijkstra\'s algorit

8条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 08:36

    You can just use a namespace instead of having a class with all static members.

    Alg.h:

    namespace Alg
    {
       void dijkstra();
    }
    

    and in Alg.cpp

    namespace Alg
    {
       void dijkstra()
       {
         // ... your code
       }
    }
    

    in main.cpp

    #include "Alg.h"
    
    int argc, char **argv)
    {
      Alg::dijkstra();
    
      return 1;
    }
    

提交回复
热议问题