我有一个类router.cpp
,其中包含名为getShortestPath
的dijkstras算法的实现。
我想从另一个名为interface.cpp
的.cpp文件中调用此方法。
Router.h
public:
Router(vector<double>);
void getShortestPath(...):
我将 starter.h 定义为:
#include "Router.h"
class starter {
public:
static Router r;
static std::string func(std::vector<double> bbox) {
std::string a = "DONE";
return a;
}
};
//EDIT: definition of a static variable must be given outside class declaration
Router r = starter::r;
和 interface.cpp ,我要在其中呼叫getShortestPath
:
starter starter;
std::vector<double> bbox;
//starter::router =
starter::r.getShortestPath(); // ERROR HERE "undefined reference to 'starter::r'
如何正确定义路由器?
我该如何克服这个问题?任何建议,将不胜感激。
编辑:
在提供有用的评论后,请找到上面的静态变量的更新定义。
这给我留下了与以前相同的错误:
在starter::r
对starter::r.getShortestPath();
的未定义引用