错误“未终止的条件指令”;在交叉引用标题中 [英] Error "Unterminated conditional directive" in cross-referencing headers
问题描述
标题中有两个相互关联的类:
There are two classes that are related to each other in their headers:
PlotMarker
#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
程序编译良好,但是出现错误错误:
,并且未突出显示IDE中的类代码,因为 #ifndef
中未终止的条件指令
The program is compiled well, but it's got a error error: unterminated conditional directive
in #ifndef
and the code of classes in the IDE isn't highlighted because of it.
如果我删除了PlotMarker标头中的 #include plotter.h
或 #include plotmarker.h
,Qt Creator照常突出显示代码,但是由于有关无效使用不完整类型的错误,编译失败。
If I remove #include "plotter.h"
in PlotMarker's header or #include "plotmarker.h"
in Plotter's header, Qt Creator highlights the code as usual, but the compilating fails because of errors about invalid use of incomplete type.
请问我怎么了?我认为是因为错误的标头交叉引用,但我遇到了此
Could you please tell me what's wrong? I think it's because of wrong headers cross-referencing, but I ran into this and it didn't help me.
推荐答案
问题已解决。
我只是将 #include
中的一个从标题移到了源文件,并且已经起作用了。
I just moved one of #include
from the header to the source file, and it has worked.
plotmarker.h
#ifndef PLOTMARKER_H
#define PLOTMARKER_H
#include <QObject>
class Plotter;
class PlotMarker : public QObject
{
// ...
Plotter* m_attachedPlot;
// ...
};
#endif // PLOTMARKER_H
// ...
plotmarker.cpp
#include "plotmarker.h"
#include "plotter.h"
// ...
这篇关于错误“未终止的条件指令”;在交叉引用标题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!