What's new

C/C++ Need help with using multiple source files with header files

Medaka

Medaka

Getting There
Messages
391
Reaction score
373
Points
185
Sin$
0
Hello, I can't seem to understand how these work. I mean, I kind of get it.

> Create CPP and header files (http://image.prntscr.com/image/be62303e5cbd4418a99467e3679a9a95.png)
> Include the header files in the source files(game.h included in game.cpp, entity.h included in entity.cpp, etc..)

But I'm very confused because on my game_s struct object, if I don't do: static game_s game; instead of extern game_s game; it won't work. I really need help understanding how this works, thanks.
 
S

Sketch

Enthusiast
Messages
531
Reaction score
278
Points
170
Sin$
7
Declaring a variable as static basically says that it's only for that source file whereas declaring it as extern is saying that it exists somewhere else. However, if you didn't declare it anywhere else then it will not compile.

(Yes, I could have actually explained it properly but I'm unsure of exact question.)

I'd be able to give more input but I'm still a little bit confused on whether or not I interpreted your question correctly.
 
Last edited:
Top Bottom
Login
Register