![]() |
|
#1
|
|||
|
|||
pointer to a member functionHi!
i have a pointer CPP / C++ / C Code:
and i send this pointer to a member function commandGoto in this part of code CPP / C++ / C Code:
CPP / C++ / C Code:
i think it is something related to call by reference but i could not realize how i shall do this. thanks... |
|
#2
|
|||
|
|||
|
Quote:
Three ways come to mind: 1. Have the function commandGoto() return a pointer to ListNode, then CPP / C++ / C Code:
CPP / C++ / C Code:
2. (The old-fashioned C way) Make the second argument of commandGoto() a pointer to a pointer to ListNode and invoke it with &temp (where temp is a pointer to ListNode) 3. (The new-fangled C++ way) Make the second argument of commandGoto() a reference variable. The effect will be the same as number 2.,above, but the notation will be slightly less confusing (according to some people). In cases like this, where the function only has to return one value, I personally (usually) prefer number 1. That's what functions are really good at: returning a value. (But that's just me --- Your Mileage May Vary). Regards, Dave |
|
#3
|
|||
|
|||
|
before i had posted my question i have tried all of the things that you have said (davekw7x) but in the first way that you told i had forgotten to make
CPP / C++ / C Code:
CPP / C++ / C Code:
Now it works fine thanks!!! But i have a quesitonmark in my mind?? i did try the other two several times and also after you said (davekw7x) but they do not work!! is there any reason for that come to your mind??* Again thanks a lot for your assist... |
|
#4
|
|||
|
|||
|
Quote:
Let's see, now --- I'll make a list of all of the ways that something won't work. On second thought, forget it: life is just too short. But seriously, folks, they can work; making them work is left as an exercise for the student. Using pointers to pointers is easy to mess up. Using reference variables is easy to mess up. Don't ask me to list all of the ways that I have ever messed up. Either method can be used when you want a function to return more than one thing. Regards, Dave |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Include] Doubly-linked List | dsmith | C Programming Language | 6 | 14-Apr-2006 13:12 |
| [Tutorial] GUI programming with FLTK | dsmith | FLTK Forum | 10 | 03-Oct-2005 15:41 |
| Why static member function cannot be virtual in C++ | Poolan | C++ Forum | 1 | 20-Nov-2004 09:51 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The