Actually I've been using #pragma once nicely and it did it's job well. However, when you write something like
##### classA.h ####
#include "classB.h"
class A
{
B Member;
};
#### classB.h ####
#include "classA.h"
class B
{
A Member;
};
MSVC will get confused.
I solved the issue after having an epiphany 15 minutes ago by using only pointers in the declaration of the classes. To declare a pointer you don't have to have included the class definition since the compiler doesn't care what the pointed to object looks like. In the .cpp file, where I actually use the pointer, I can include however many .h files I want.
So the above example looks like this now:
#### classA.h ####
class B;
class A
{
B* pMember;
};
#### classA.cpp ###
#include "classA.h"
#include "classB.h"
// Have fun with both A and B here!
#### classB.h ####
class A;
class B
{
A* pMember;
}
#### classB.cpp ####
#include "classB.h"
#include "classA.h"
// Have fun with both A and B here!
I've been looking at the issue above for 2 days straight, alternating between looking at google's unrelated search results about people who had spelling mistakes in their declarations and fudging around with my code by myself.
It's wonderous how suddenly you see a solution to problem you've been looking at for so long.
Vain