I have 3 classes.
The main class is Form1
The other two are Form2 & Class3
I included Form2 & Class3 in Form1, I mean I have in Form1 the following:
#include "Form2.h"
#include "Class3.h"
Also, in Form2 I included Class3, so I have in Form2 the following:
#include "Class3.h"
But I get redefine error, how I can solve this.
I always face like this issue, some time it is enough to include headers in stdafx.h but sometime doesn’t work. So the other question how I can utilize and make use of stdafx.h which is created by default in my C++/CLI winform project?
Try adding this in Class3.h:
That should work
So you understand what is going on, what this is doing is preventing your Class3.h to redefine everything if it has already been done. In your program, Form1 uses Class3, but so does Form2. The first time Form2 is included, so is Class3, then, the next line you try to include Class3 again and then you get a redefinition error.
Hope that makes it clear for you
p.s.: I strongly recommend that you do this with all your .h files, though