0

I have big project in which appeared extremely incomprehensible mistake, after which I created a new project repeated it:

struct of project is simple:

main.cpp
first.h
second.h

first.h

#ifndef FIRST_H
#define FIRST_H

#include "second.h"

class first
{
public:
    first();
};

#endif // FIRST_H

second.h

#ifndef SECOND_H
#define SECOND_H

#include "first.h"

class second
{
public:
    second();
};

#endif // SECOND_H

Everything is quite logical, but Qt Creator thinks quite differently:

D:\WinFiles\Documents\QT\DELME1\DELME1\second.h:1: error: unterminated conditional directive

I am a bit at a loss case as for inheritance this construction is needed

J. Calleja
  • 4,855
  • 2
  • 33
  • 54
Vlad
  • 17
  • 5
  • #ifndef FIRST_H #define FIRST_H #endif // FIRST_H should solve this problem. Or not? – Vlad Dec 29 '18 at 06:34
  • No, Include guards don't solve the circular include problem. – drescherjm Dec 29 '18 at 06:41
  • I have no dependencies in classes, only the inclusion of one file in another. – Vlad Dec 29 '18 at 06:46
  • You have dependencies, Class `first` depends on `second` and class `second` depends on `first`. Please take a look at duplicate link, should solve your problem. – HMD Dec 29 '18 at 06:48
  • Don't understand anything! Microsoft Visual Studio 2017 compiled this code and did not find anything strange in it: **========== Build: successful: 1, with errors: 0, no change: 0, skipped: 0 ==========** – Vlad Dec 29 '18 at 07:04
  • Does this mean it's time to change the compiler to MSVC Compiller?) – Vlad Dec 29 '18 at 07:13
  • A cool situation happens when you learn C ++ at one compiler, and then you compile code under another and everything crashed. – Vlad Dec 29 '18 at 07:48
  • Which compiler and version are you using? – J. Calleja Dec 29 '18 at 10:53

1 Answers1

0

Problem solving for MinGW compiler:

//first.h
#ifndef FIRST_H
#define FIRST_H

class second;
class first
{
public:
    first();
};

#endif // FIRST_H

//second.h
#ifndef SECOND_H
#define SECOND_H

class first;
class second
{
public:
    second();
};

#endif // SECOND_H

The second solution is to use MSVC compiller for qt which will guess what needs to be done by itself and compiled all of the examples correctly.

Vlad
  • 17
  • 5