*this problem (help?)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

*this problem (help?)

 
0
  #1
Oct 4th, 2008
  1. void myClass<temp_Type>::myFunction(myClass<temp_Type>* &firstClass, myClass<temp_Type>* secondClass)
  2. {
  3.  
  4. }
  5.  
  6. [call]
  7.  
  8. myFunction(*this, &secondClass);

I think I am fundamentally challenged on the "this" qualifier. I want to pass a pointer to the current object(ie the object I am calling the function from), but am stuck trying to pass the "this". Are there any other methods to go about something such as this?
Last edited by chococrack; Oct 4th, 2008 at 2:29 pm.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: *this problem (help?)

 
0
  #2
Oct 4th, 2008
If you want to pass POINTER to current object, then it is simply this , and not *this
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,433
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1471
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: *this problem (help?)

 
0
  #3
Oct 4th, 2008
this is a pointer, *this dereferences the pointer. So if you want to pass a pointer just don't use the asterisk. myFunction(this, &copyClass); That doesn't mean it will solve your problem, but that's how to pass pointers.

That looks like a recursive function call, I doubt you even need to pass this pointer because the compiler will do that anyway.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: *this problem (help?)

 
0
  #4
Oct 4th, 2008
Since I need to change the actual object itself, I would need to do something along the lines of &this

Unsure of if its legal or not, going to try it now. Thanks for the quick replies.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: *this problem (help?)

 
0
  #5
Oct 4th, 2008
From http://www.codersource.net/cpp_tutor...s_pointer.html

this pointers are not modifiable.

So I wouldn't recommend that
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: *this problem (help?)

 
0
  #6
Oct 4th, 2008
Nah, &this is illegal, compiler fusses at me Time for a new approach ::cracks fingers::
Last edited by chococrack; Oct 4th, 2008 at 2:57 pm.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: *this problem (help?)

 
1
  #7
Oct 4th, 2008
The special pointer this has type Class*const (not Class*) so you can't pass this as an argument to myFunction.

It seems the myfunction member has a slightly unusual signature with the 1st parameter of type "a reference to a pointer to myClass<temp_Type>". Can you explain what do you want to do with the 1st parameter of this member function?
Last edited by ArkM; Oct 4th, 2008 at 2:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: *this problem (help?)

 
0
  #8
Oct 6th, 2008
this is certainly a bugger. I ended up having to re-route what I was trying to accomplish. I do appreciate the help.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,698
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 730
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: *this problem (help?)

 
1
  #9
Oct 6th, 2008
>I ended up having to re-route what I was trying to accomplish.
What were you trying to accomplish? The way I'm reading your problem, you're confused about what this is. A pointer to the current object is always available from a non-static member function; you don't have to pass it explicitly.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC