Archived

This topic is now archived and is closed to further replies.

Squirell

Variables across multiple sources

Recommended Posts

I have a problem with using the same variables in to different sources of the same project in Dev C++. Lets say i have to .cpp files, ai and game. How can i use variables from ai in game or game in ai. I can get functions to work, just not variables that i declare at the top of the source.

Share this post


Link to post
Share on other sites
Google ''extern tutorial c'' or something like that for more info. Really, it is best that you don''t focus much on that. If you are going to be using c++ you really will need to learn a bit of OOP.

Share this post


Link to post
Share on other sites
Wanting to share isolated variables across source files is not a sign of doing OOP. You want to be specifying an AI class and a Game class, and create new AI instances within your Game logic or vice-versa. :/

Share this post


Link to post
Share on other sites
in your header, declare the variable as:
extern float poop;
or whatever type/name you want.

then in the cpp of that header, make the global variable:
float poop;

then in the other cpp, include the previous header and you can use poop to your delight.

Share this post


Link to post
Share on other sites