在它们的标题中有两个相互关联的类:
绘图标记
#ifndef PLOTMARKER_H
#define PLOTMARKER_H
#include <QObject>
#include "plotter.h"
class Plotter;
class PlotMarker : public QObject
{
// ...
Plotter* m_attachedPlot;
// ...
};
#endif // PLOTMARKER_H
绘图仪
#ifndef PLOTTER_H
#define PLOTTER_H
// ...
#include "plotmarker.h"
// ...
class PlotMarker;
class Plotter : public QQuickPaintedItem
{
// ...
QLinkedList<PlotMarker*> m_markerList;
// ...
};
#endif // PLOTTER_H
该程序编译良好,但在 --- 中出现错误 error: unterminated conditional directive
#ifndef
并且因此没有突出显示 IDE 中的类代码。
如果我在 PlotMarker 的标头中删除 #include "plotter.h"
#include "plotmarker.h"
在 Plotter 的标头中删除 — ,Qt Creator 会像往常一样突出显示代码,但是由于有关无效使用不完整类型的错误,编译失败。
你能告诉我有什么问题吗?我认为这是因为错误的标题交叉引用,但我遇到了 这个,它并没有帮助我。
原文由 Nikita 发布,翻译遵循 CC BY-SA 4.0 许可协议
问题已经解决了。
我刚刚将
#include
之一从头文件移动到源文件,它已经工作了。绘图标记.h
// …
绘图标记.cpp