I am new to C++ and have a question about include files. I have some classes that I want to share between the main and other classes also. So I include the reference in my main and also in my class. However, this causes a compiler error. If I comment out one reference than it works fine, but as soon as there are two references to a .h file it throws an error.

I know this is going to be elementary, but I have searched and can't seem to figure this out. Any help would be appreciated.

Thanks

Post your code.

Thanks for your response. I just figured it out and here is what I did:

At the very top of the .h file I added these two rows:
#ifndef SURVEYMASTER_SURVEY1
#define SURVEYMASTER_SURVEY1

The upper case words can be replaced with anything meaningful for your project.

At the very bottom add this row:
#endif

It turns out that without these three lines the compiler will try to compile the .h file twice which creates an error.

Thanks again and I hope this helps someone else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.