![]() |
|
#1
|
|||
|
|||
Setting a pointer member thru a functionHi! I have a class that has a pointer member (elem1). I was wondering if I could use a function returning a reference (El below) to change the pointer to point to some other Element object?
CPP / C++ / C Code:
Thanks, Michelle |
|
#2
|
||||
|
||||
Re: Setting a pointer member thru a functionCould you give a fuller description of what you want to do? I may be just me, but I only see half a description here.
__________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#3
|
|||
|
|||
Re: Setting a pointer member thru a functionHi Walt!
This is what I want to do: CPP / C++ / C Code:
main program would be: CPP / C++ / C Code:
Thanks, Michelle |
|
#4
|
||||
|
||||
Re: Setting a pointer member thru a functionThat's beyond my C++ knowledge... Paramesh? I know you're on line..... and probably answering already
__________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#5
|
||||
|
||||
Re: Setting a pointer member thru a functionYes!
You can do that. With just a little bit change: For example, consider that the element is int. Here is a sample code: CPP / C++ / C Code:
Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#6
|
|||
|
|||
Re: Setting a pointer member thru a functionHi Paramesh!
Thanks! That helps a lot! Michelle |
|
#7
|
|||
|
|||
Re: Setting a pointer member thru a functionHi Paramesh!
I just noticed that that code changes the value of the data pointed by elem1, but not the pointer (it's still the same address in memory). What I want to change is the pointer to point someplace else. Thanks, Michelle |
|
#8
|
||||
|
||||
Re: Setting a pointer member thru a functionFor that, add an extra member function like this:
CPP / C++ / C Code:
Then, in your main function, you can do like this: CPP / C++ / C Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
Recent GIDBlog
Toyota - 2008 July Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Tutorial] Function Pointers | aaroncohn | C++ Forum | 4 | 17-Feb-2006 11:33 |
| [Tutorial] GUI programming with FLTK | dsmith | FLTK Forum | 10 | 03-Oct-2005 15:41 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| [Tutorial] Pointers in C (Part II) | Stack Overflow | C Programming Language | 0 | 27-Apr-2005 17:36 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The