![]() |
|
#1
|
||||
|
||||
Passing multiple objects in functionsI'm confused w/ OOP. In my code below (which isn't complete yet, I know), what I want to do is create an object (e.g. line1) and pass it to the function that lets the user enter the slope and a point on the line, thereby creating a new line, if that makes sense.
What I'm confused about is how to pass the slope and point back to the main function. That is, having passed line1 to the function, how do I get line.slope and line.point back? I thought about using call-by-reference paramenters (create line.slope and line.point and pass them to the function with the '&' ) but I'm not sure I can legally do that. I'm also attaching my class headers and implementation files. CPP / C++ / C Code:
__________________
Common Sense v2.0-Striving to make the world a little bit smarter. |
|
#2
|
|||
|
|||
|
How about using global variables.? They will be available globally throughout your program.
You can extern them to other files if you need to modify their value in multiple source files. It may not be efficient but not a bad choice for small programs. Thanks, |
|
#3
|
||||
|
||||
|
Quote:
__________________
Age is unimportant -- except in cheese |
|
#4
|
|||
|
|||
|
Quote:
I think that this is really bad advice whatever the size of the program. It is almost never necessary to use global variables. Pass pointers to the variables or structs, or whatever, to any functions where they need to modify the thing. Some day you may be given a program to debug. If the program has lots (or even a few) global variables, you will surely think of lots of really bad words to say to the person who wrote that program. Regards, Dave |
Recent GIDBlog
Meeting the populace by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| controling dialog objects & multiple source files | omills | MS Visual C++ / MFC Forum | 0 | 14-Jul-2004 23:30 |
| Passing strings in functions..HELP please... | mgdpetter | C Programming Language | 2 | 24-May-2004 22:02 |
| Help on passing in arrays in functions? | nusstu | C Programming Language | 10 | 02-Apr-2004 10:42 |
| Passing Pointers To Pointers in Functions | elumira | C Programming Language | 8 | 05-Mar-2004 21:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The