C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how do I make variables global??

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Colleen
Guest





PostPosted: Mon Apr 19, 2004 5:26 pm    Post subject: how do I make variables global?? Reply with quote



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





PostPosted: Tue Apr 20, 2004 5:12 am    Post subject: Re: how do I make variables global?? Reply with quote



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





PostPosted: Wed Apr 28, 2004 4:12 pm    Post subject: Re: how do I make variables global?? Reply with quote



Colleen wrote:

Why are you posting to a German group in English Smile?

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.