ive created class A and class B, im trying to set a vector of type B to and a vector of type A to B
You create a circular dependency between your classes. This is usually bad, especially in C ++.
The compiler to compile A must know the definition of B (#include "Bh"). Unfortunately, heading B contains a reference to class A (here a circular link). The compiler cannot handle this situation, since the header is already included in the current TU (see Include guard).
Although circular references are often a symptom of poor design, you can ultimately overcome the problem using a forward declaration. For example, you can change B as follows:
#ifndef B_H_
Using a direct declaration basically tells the compiler that type A will be defined somewhere else. The compiler can rely on this fact, but it knows nothing about A (in particular, it ignores the size of A and its methods). Therefore, inside B, if you have A declared forward, you can only use pointers to classes A (pointers always have the same size), and you cannot call any methods of class A from the inside.
source share