I
I
ivandzemianchyk2014-07-23 14:07:19
Programming
ivandzemianchyk, 2014-07-23 14:07:19

You need to divide the code into C++ files. Where is the mistake?

Main.cpp
#include "a.hpp"
a.hpp

#ifndef  A_HPP_
#define  A_HPP_
#include "b.hpp"
#include "c.hpp"
#include "d.hpp"
class A: public B, public C
{

D ddd;
};
#endif

a.cpp
#include "a.hpp"
B.hpp
#ifndef  B_HPP_
#define  B_HPP_
#include "d.hpp"
class B{
...
D ddd;
};
#endif

C.hpp
#ifndef  C_HPP_
#define  C_HPP_
#include "d.hpp"
class C{

D ddd;
};
#endif

d.hpp
#ifndef D_HPP_
#define  D_HPP_
class D{
};
#endif

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ivandzemianchyk, 2014-07-23
@ivandzemianchyk

Thanks for answers.
Thanks for answers.
The solution was not where I was looking for it. The fact is that in the d.hpp file I described all the functions of class D in the same file (there were just 2 of them and I did not want to throw them into the .cpp file)
After transferring to .cpp everything worked as it should.
If there is still a kind soul, then I will be glad to know the answer to the questions:
1. What is the difference between delaration and description of functions in a different file and in two?
2. Why did the description in one file work in some situations, but not in others?

S
Sergey, 2014-07-23
Protko @Fesor

en.wikipedia.org/wiki/Include_guard
Well, somehow you have thrashers, there are not enough classes and all that...

N
niosus, 2014-07-23
@niosus

I will separately write the same as @EndUser . Don't put a semicolon after #endif.
Well, in appearance, everything else should be correct. I don't see a problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question