 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Colleen Guest
|
Posted: Mon Apr 19, 2004 5:26 pm Post subject: how do I make variables global?? |
|
|
Maybe anyone can help me to do this, or just tell me it's not
possible...
I have data that I read from a file in my 'int main()'. Now I want to
make calculations using these data in several procedures. Since
writing the code for calling all the various data one by one in each
procedure is tedious and messy, I would like to find a way how to make
the data global instead, so that all the procedures know the data.Is
that possible?
Thanks for help.
Greetings,
W.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Daniel Albuschat Guest
|
Posted: Tue Apr 20, 2004 5:12 am Post subject: Re: how do I make variables global?? |
|
|
Colleen wrote:
| Quote: | I have data that I read from a file in my 'int main()'. Now I want to
make calculations using these data in several procedures. Since
writing the code for calling all the various data one by one in each
procedure is tedious and messy, I would like to find a way how to make
the data global instead, so that all the procedures know the data.Is
that possible?
|
Let's assume your data is of type `Data' and this type is declared
in data.h. Then you would do something like this:
in main.cpp:
#include "utils.h"
#include "data.h"
void read_data( Data &data ) {
/* ... */
}
int main() {
Data data;
read_data(data);
}
in utils.h:
#include "data.h"
void do_calculations( Data &data );
in utils.cpp:
#include "utils.h"
void do_calculations( Data &data ) {
/* do some calculations on the precious data */
}
cu,
Daniel Albuschat
P.S.: This is a german newsgroup.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Marco Budde Guest
|
Posted: Wed Apr 28, 2004 4:12 pm Post subject: Re: how do I make variables global?? |
|
|
Colleen wrote:
Why are you posting to a German group in English ?
| Quote: | I have data that I read from a file in my 'int main()'. Now I want to
make calculations using these data in several procedures. Since
writing the code for calling all the various data one by one in each
procedure is tedious and messy,
|
Read a book about OOP and/or use structs and classes.
| Quote: | I would like to find a way how to make
the data global instead,
|
Never made any data global. This makes programs nearly
unreadable.
| Quote: | so that all the procedures know the data.Is
that possible?
|
Learn a new language feature called "class"?
cu, Marco
--
S: Minolta: Winkelsucher (VN), VC-9
E-Mail: mb-news-b<ät>linuxhaven.de
Deutsches Linux HOWTO Projekt: http://www.linuxhaven.de
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|