redefinition of 'class Data'
previous definition of 'class Data'
---note--- Data is a class that i declare in a header file
redefinition of 'class Data'
previous definition of 'class Data'
---note--- Data is a class that i declare in a header file
you probably don't have include guards. you need to either say
Code:#pragma once or #ifndef MY_HEADER_FILE #define MY_HEADER_FILE class Data { }; #endif // MY_HEADER_FILE
thanks it worked, but what exactly are include guards and what instance do you need to use them
Usually they are used on the top and bottom of a file. Think for example a common header file, like <stdlib.h>. You might included it in a lot of files. If you use guards, it will just use it once, which is your intention, the compiler just doesn't do this automatically for you.
To use it to skip a piece of code can be tricky and I won't recommend it. You might have two Data class, but different. In this case you should use namespaces for example or rename one to solve your problem. If you have to have the exact same class, then you should write it on a separate file and include it when needed.
Technically speaking, what happens is that the pre-compiler will check if MY_HEADER_FILE variable is defined. If it is it will scroll down to #endif. So it will skip the whole Data class. If it is not defined it will #define it. Now, if you have another header file with the same Data class, it will skip it, giving no errors. So when used on a whole file, you simply skip the whole file.
#pragma once does basically the same thing as include guards, except that it is non-standard, i.e. is only supported by specific compilers.