C ++ class differences and class names include the

A.h

A {class
public:
    B * m_Low;
}
. 1
2
. 3
. 4
it will compile error, because there is no definition of B

#include "B.h"

A {class
public:
    B * m_Low;
}
. 1
2
. 3
. 4
. 5
. 6
but that, once defined modification B, then there would be recompiled Ah, Ah is used causes all files need to be recompiled, thus causing compiled dependence, increasing the compile time on large projects, if many such places, it may even extreme increase compile time. To avoid this, we can do it with class B;

A.h


class B;
class A{
public:
    B* m_;
}
1
2
3
4
5
6
A.cpp

#include "Bh"
#include "Ah"
// embodied
. 1
2
. 3
in Ah declared class B, include in the A.cpp Bh, Bh changes even so, Ah does not change, the other file by using the Ah there is no need to recompile, so you can avoid compiler dependent, in large projects will save a lot of time
 

Published 352 original articles · won praise 115 · views 130 000 +

Guess you like

Origin blog.csdn.net/Aidam_Bo/article/details/105230272