LNK2005 error redefinition

I'm getting a LNK2005 error due to redefinition of some functions.  The project has a main (test.cpp), two classes (myclass1.h, myclass1.cpp, myclass2.h, myclass2.cpp), and another header file (morefuncs.h) that is not a class but contains some functions.

I've used #pragma once in all header files.

The test.cpp #includes both header files for the classes.

If I include the header file for the additional functions, #include morefuncs.h into only one of the class header files, everything is fine.  However if I try to include morefuncs.h into the second class, I get the above linker redefinition error.  I'm assuming this is becasue the morefuncs is not a class but simply a header file that contains functions.

I'd rather not make morefuncs a class. Is there a way to include it into multiple other classes without a redefinition problem?
JohnSantaFeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
#pragma once prevents h-file to be included twice to the same source file. But it doesn't prevent h-file to be included number of times to different source files in the project. If h-file contains function implementations, this causes linker error.
You have one the following options:
1) Move function implementations to additional cpp file and leave only prototypes in h-file
2) Declare all functions in h-file as inline
3) Declare all functions in h-file as static
4) Divide h-file on two parts: declaration and implementation:

// declaration part
// function prototypes

#ifdef IMPLEMENTATION
// function bodies
#endif

Include this h-file to number of source files, and define only once IMPLEMENTATION:

#define IMPLEMENTATION    // only in one source file
#include "MyFile.h"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.