gpt4 book ai didi

c++ - g++ 警告,使用了内联虚函数但未定义

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:07:13 25 4
gpt4 key购买 nike

我目前遇到 问题警告我无法摆脱。我的代码运行良好,但此警告不断弹出:

ChildModel.h:136:24: warning: inline function virtual int ChildModel::getLinkCost(const Link&) const used but never defined [enabled by default]

我目前找到了this post在 S.O 上,有同样的问题,但答案是特定于库的(定义了一些东西)所以它对我不起作用。

我的代码如下:

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;
};

ChildModel 唯一重新定义的函数是Model::getLinkCostModel::getLinkCost 方法只被一个方法调用模型。所有方法都在 C++ 文件 Model.cpp 中定义。

最佳答案

来自 http://en.cppreference.com/w/cpp/language/inline

The definition of an inline function must be present in the translation unit where it is called.

如果要在 .cpp 文件中定义函数,则必须从 .h 文件中删除 inline 说明符。

关于c++ - g++ 警告,使用了内联虚函数但未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24635656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com