Static Functions in C++

前端 未结 8 1260
野趣味
野趣味 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:49

    You are confusing the 'static' keyword for local functions, with the 'static' keyword used in a class to make a function a class function and not an object function.

    Remove static the first line of Alg.cpp and in the header file. This will allow Alg.o to contain global symbols that main can refer to and the linker can link.

    You still need to call Alg::dijkstra() as was stated by @egur.

    After this you may still get errors. The way you are using Alg:: is more like a namespace than a 'class' definition.

提交回复
热议问题