If it compiles, it's only because you only have one compilation unit (where your main function is). If you were to use your FowardEulerSolver header or AbstractOdeSolver in more than one compilation unit (more than one ".cpp" file, handwaving some details), then you would get multiple definition errors. You can solve these errors by putting your class's function definitions in their own .cpp files, similar to how you originally were doing it, but constructor definitions also belong there, and you should have header guards as you do now. Or, mark all separated function definitions in the header as being
inline, which allows the linker to assume the multiple definitions match.
Your cpp file that contains main
should not have header guards.
This part of it doesn't even do anything:
1 2 3
|
#ifndef __FORWARDEULERSOLVER_H__
#endif // !__FORWARDEULERSOLVER_H__
|
//Should an include guard be included here? |
Yes, you should put #include guards in any header file where it might be indirectly or directly #included more than once. It makes it more portable.
Also, just from a readability standpoint, you have a typo. Foward should be Forward.
Small note: Despite the fact that various tutorials may do it, you should not start your macros with two underscores or an underscore + capital letter. It's technically not allowed (reserved), although the chances of a naming conflict here happening are approximately 0.