I'm still having trouble with the #include

I remembered to add the “#ifndef” stuff to my Character class as soon as I realized I was going to need to “#include” character.h when I setup the Character* pointer in my Enemy class.

So far so good.

But the problem is that since I’m not “#including” the character.h stuff again, I’m getting all kinds of errors in character.cpp when it tries to “#include” character.h.


This is the instructor's code:

character.h:

This is my code:

character.h:

image

character.cpp:


Q:


Is there a way to ensure it’s only #included twice and only at these parts? Should I define more variables somewhere? How come the instructor’s code isn’t having this same problem.

Like me, he also “#includes” chartacter.h in two important places: main.cpp and character.cpp

Instructor's main.cpp #includes:

image

My main.cpp #includes:

image

Not sure what I’m doing that’s dramatically different.

Also, and maybe I should have pointed this out earlier (no pun intended), but the game runs fine if I hit F5. These errors that VSCode is showing don’t seem to be influencing gameplay at all, which I also do not understand.

Okay, i closed VSCode and re-opened it and now it’s perfectly happy. All the red squigglies went away.

I think I hate VS Code.

5 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms