Question

I have successfully added a dynamic library to a program, but when I try to include the header file in a second file of the project I get errors about class redeclaration. I will add more info if this isn't enough

Was it helpful?

Solution

You need to put guards into your header so it isn't included multiple times. For file 'my.h', you can add something along the lines of:

#ifndef MY_H
#define MY_H

// Header declarations here

#endif

This way, you can include the .h file multiple times but it will only be included the first time.

OTHER TIPS

An #include will replace the #include statement with the files content; having multiple #include's of the same file will therefore redefine the elements multiple times. The typical way is a safeguard like:

/* file foo .h */
#ifndef _FOO_H
#define _FOO_H

/* content */

#endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top