Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,911 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,184 people online right now. Registration is fast and FREE... Join Now!




Passing global variables

 
Reply to this topicStart new topic

Passing global variables

rpm279
7 Jan, 2008 - 02:03 PM
Post #1

New D.I.C Head
*

Joined: 7 Jan, 2008
Posts: 1

I am trying to do an assignment where I declare at first 4 variables (actually they are linked lists), and try to pass them through 10 functions where only the last one actually uses them.
Is there a way so that all my functions don't have to hold 4 parameters which they do not use, but they only pass? a kind of global variable accessed from anywhere (even if my functions are located in a header file)?

I tried to declare them as global variables outside the main, and I tried to declare them on a separate namespace, but it still gives me errors

Thank you for your time.
User is offlineProfile CardPM
+Quote Post

lockdown
RE: Passing Global Variables
7 Jan, 2008 - 02:18 PM
Post #2

D.I.C Regular
Group Icon

Joined: 29 Sep, 2007
Posts: 376



Thanked: 1 times
Expert In: PC, Support

My Contributions
Global variables do not need to be passed since they are global. Any were in your application will be able to access them even when in different functions.

Really what the assignment wants you to do is pass local variables declared in the main function to the rest of the functions. Each function then pass them onto the next and so on.

You need to first declare 4 variables and just call the next function passing those variables to them.

Also post your code up so we can help spot ur errors.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 01:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month