Error “Unterminated conditional directive” in cross-referencing headers

我们两清 提交于 2019-12-07 14:26:24

问题


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

Plotter

#ifndef PLOTTER_H
#define PLOTTER_H

// ...
#include "plotmarker.h"
// ...

class PlotMarker;

class Plotter : public QQuickPaintedItem
{
    // ...
    QLinkedList<PlotMarker*> m_markerList;
    // ...
};

#endif // PLOTTER_H

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.

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.


回答1:


The problem is solved.

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"
// ...


来源:https://stackoverflow.com/questions/51172635/error-unterminated-conditional-directive-in-cross-referencing-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!