我目前遇到一个问题,关于g++警告信息,我无法摆脱。我的代码完全正常运行,但是这个警告一直弹出:
ChildModel.h:136:24: 警告:使用但未定义的虚函数virtual int ChildModel::getLinkCost(const Link&) const [默认情况下启用]
我在S.O上找到了this post,与我有相同的问题,但是答案针对库(定义某些内容),所以对我不起作用。
我的代码如下:
class Model {
public:
virtual inline int getLinkCost(Link const& link) const;
};
class ChildModel: public Model {
public:
/** Warning on the line bellow: **/
virtual inline int getLinkCost(Link const& link) const;
};
< p > ChildModel
重新定义的唯一函数是 Model::getLinkCost
,而 Model::getLinkCost
方法仅由 Model
的一个方法调用。所有方法都在 C++ 文件 Model.cpp
中定义。
inline
没有任何作用。关于警告:它告诉你该函数未定义。因此,请展示你的Model.cpp
(以及如何编译/链接你的代码)。 - Konrad Rudolphinline
修饰符,要么将其定义在头文件中。 - Mike SeymourModel.cpp
中定义了ChildModel :: getLinkCost
和Model :: getLinkCost
,并且唯一使用Model :: getLinkCost
的函数是Model
的一个方法,也在Model.cpp
中定义? - Holt