jncs@uno.edu (04/17/91)
I am learning C++ having experience with Smalltalk. My question refers to the
use of the pseudovariable "this". In Smalltalk, one can use the pseudovariable
self, to refer to the object which received the message. In particular, one
can use it inside of a method of one of the superclasses of the object, to
send messages to it. (something like, [self amessage]). This allows to write
methods at the superclass level which send messages to invoke methods which
are implemented at the subclass level.
Example : can I write :
int C::foo (...)
{
...
this.message
...
}
where "message" is a virtual function declared in class C.
Thanks
J. Nino
Computer Science Department
Univ. of New Orleansml27192@uxa.cso.uiuc.edu (Mark Lanett) (04/18/91)
jncs@uno.edu writes: >Example : can I write : > int C::foo (...) > { > ... > this.message > ... > } >where "message" is a virtual function declared in class C. Yes, this and self are similar. Note that this is a pointer, so the usage is this->message (); this is in fact optional: message () alone will work. -- //----------------------------------------------------------------------------- Mark Lanett ml27192@uxa.cs.uiuc.edu
mvm@jedi.harris-atd.com (Matt Mahoney) (04/18/91)
In article <0094742D.B7B638A0@uno.edu> jncs@uno.edu writes: >Example : can I write : > > int C::foo (...) > { > ... > this.message > ... > } > >where "message" is a virtual function declared in class C. The correct syntax is: this->message(); or simply message(); -------------------------- Matt Mahoney, mvm@epg.harris.com #include <disclaimer.h>
gdtltr@brahms.udel.edu (root@research.bdi.com (Systems Research Supervisor)) (04/18/91)
In article <1991Apr17.175658.13334@ux1.cso.uiuc.edu> ml27192@uxa.cso.uiuc.edu (Mark Lanett) writes: =>jncs@uno.edu writes: => =>>Example : can I write : =>> int C::foo (...) =>> { =>> ... =>> this.message =>> ... =>> } => =>>where "message" is a virtual function declared in class C. => =>Yes, this and self are similar. Note that this is a pointer, so =>the usage is this->message (); this is in fact optional: message () =>alone will work. Unless, of course, you do something stupid like making a local variable which is also named "message". Then the "this" reference would be necessary to force the scope into the class rather than the member function. Gary Duzan Time Lord Third Regeneration -- gdtltr@brahms.udel.edu _o_ ---------------------- _o_ [|o o|] Two CPU's are better than one; N CPU's would be real nice. [|o o|] |_o_| Disclaimer: I AM Brain Dead Innovations, Inc. |_o_|
gdtltr@brahms.udel.edu (root@research.bdi.com (Systems Research Supervisor)) (04/18/91)
In article <20525@brahms.udel.edu> gdtltr@brahms.udel.edu (root@research.bdi.com (Systems Research Supervisor)) writes: =>In article <1991Apr17.175658.13334@ux1.cso.uiuc.edu> ml27192@uxa.cso.uiuc.edu (Mark Lanett) writes: =>=>jncs@uno.edu writes: =>=> =>=>>Example : can I write : =>=>> int C::foo (...) =>=>> { =>=>> ... =>=>> this.message =>=>> ... =>=>> } =>=> =>=>>where "message" is a virtual function declared in class C. =>=> =>=>Yes, this and self are similar. Note that this is a pointer, so =>=>the usage is this->message (); this is in fact optional: message () =>=>alone will work. => => Unless, of course, you do something stupid like making a local variable =>which is also named "message". Then the "this" reference would be necessary =>to force the scope into the class rather than the member function. => Or just use the scope resolution operator: C::message. Gary Duzan Time Lord Third Regeneration -- gdtltr@brahms.udel.edu _o_ ---------------------- _o_ [|o o|] Two CPU's are better than one; N CPU's would be real nice. [|o o|] |_o_| Disclaimer: I AM Brain Dead Innovations, Inc. |_o_|