c++ - Qt 创建者 : “inline function used but never defined” – why?

标签 c++ qt qt-creator

为什么我在 Qt Creator 中收到此警告:` inline function 'bool Lion::growl ()' used but never defined?

我仔细检查了我的代码,并有一个声明

inline bool growl () in Lion (lion.h)

以及lion.cpp中对应的实现:

inline bool Lion::growl ()

发生了什么事?

编辑:我的假设是在 .cpp 文件中定义实际的内联方法是合法的(inline 关键字提醒编译器在其他地方寻找方法主体),或者我是搞错了?

我不想让我的头文件与实现细节杂乱无章。

最佳答案

好吧,我不知道确切的问题,但对于初学者来说:

  • 内联方法应该在头文件中实现。编译器需要知道代码才能真正内联它。
  • 在类声明中使用“inline”关键字也没有任何效果。但它也不会受到伤害。

另请参阅:c++ faq lite

关于c++ - Qt 创建者 : “inline function used but never defined” – why?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1421666/

相关文章:

linux - QTcreator交叉编译

python - 使用 PyQt 实现分割器(QtCreator 生成的文件)

c++ - thrust::tuple in reduction 的自定义最小运算符

c++ - Qt 应用程序是否具有自动垃圾收集功能?

qt - 如何将动态内容放入 QML 组件中

c++ - Qt Creator 错误 : LNK1123: failure during conversion to COFF: file invalid or corrupt

c++ - 使用 CreateWindowEx() 创建的窗口中的默认按钮

C++类转换可能吗?

c++ - Rcpp 按名称获取元素 - $ 运算符

qt - Qt中Q_D宏的作用是什么