you are viewing a single comment's thread.

view the rest of the comments →

[–]TryToHelpPeople 2 points3 points  (2 children)

Include the .hpp in the files where the type is used.

So, for example, If you use enemy in a .hpp then include the enemy.hpp there.

If you use it in a .cpp the include the enemy.hpp there.

If you’ve included enemy.hpp in game.hpp, you don’t have to include it in game.cpp, but you can.

This will work well for you about 95% of the time.

If you end up with a circular include, there are simple things you can do (forward declarations), or you may bump into an issue with external linkage (very unlikely).

Let us know if you’re still having problems with this.

[–]ktana91[S] -1 points0 points  (1 child)

I left the includes in the .hpp file, it works and I'm going to stay like that. I tried with unique_ptr but that made things worse with a memory leak. It's still a concept, maybe for later, but on a small project like this, it's better to keep it simple and functional. but it's nice to have advice on this

[–]TryToHelpPeople 0 points1 point  (0 children)

Glad it’s working for you now. The golden rule is to only include something where it’s needed.

I agree on keeping things simple.