|
-
Aug 3rd, 2001, 07:09 PM
#1
Thread Starter
Hyperactive Member
This
The keyword this represents within a class the address in memory of the object of that class that is being executed. It is a pointer whose value is always the address of the object.
It can be used to check if a parameter passed to a member function of an object is the object itself.
Taken from the cplusplus.com tutorial... I dont really understand what this sentence means...they give this example...i dont understand what's special about it...
Code:
//this
#include <iostream.h>
class CDummy
{
public:
int isitme(CDummy& param);
};
int CDummy::isitme(CDummy& param)
{
if(¶m == this) return 1;
else return 0;
}
void main()
{
CDummy a;
CDummy *b = &a;
if(b->isitme(a))
cout <<"yep, &a is b\n";
else
cout << "nope, don't know this one\n";
}
i am not sure what the this pointer is...
Thanks in advance!
Amon Ra
The Power of Learning.
-
Aug 3rd, 2001, 07:11 PM
#2
Thread Starter
Hyperactive Member
just one thing...
Code:
//this
#include <iostream.h>
class CDummy
{
public:
int isitme(CDummy& param);
};
int CDummy::isitme(CDummy& param)
{
if(¶m == this) return 1;
else return 0;
}
void main()
{
CDummy a;
CDummy *b = &a;
if(b->isitme(a))
cout <<"yep, &a is b\n";
else
cout << "nope, don't know this one\n";
}
What I dont get here, is what does the this pointer contain when i call the function: the address of *b or a?
Amon Ra
The Power of Learning.
-
Aug 3rd, 2001, 07:13 PM
#3
Thread Starter
Hyperactive Member
oups
i dont knoe why, but the ¶m shows up as¶m =)
Amon Ra
The Power of Learning.
-
Aug 4th, 2001, 01:50 AM
#4
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 04:36 AM
#5
transcendental analytic
he probably typed ¶m but it got ¶m
param is a reference, didn't you notice parksie? it should compile
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 4th, 2001, 05:39 AM
#6
Monday Morning Lunatic
Code:
CDummy a;
CDummy *b = &a;
if(b->isitme(a))
It's expecting a reference not a pointer Wouldn't passing a pointer violate the rules of referencing?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 06:32 AM
#7
transcendental analytic
Eh, well a is not a pointer right? if b is null (for some odd reason), it still fires isitme and pass a right?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 4th, 2001, 06:35 AM
#8
Monday Morning Lunatic
Ok I can't read...I thought b was a
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 06:36 AM
#9
transcendental analytic
hehehe
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 4th, 2001, 06:38 AM
#10
Monday Morning Lunatic
I really need to get a good monitor
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 4th, 2001, 06:37 PM
#11
Thread Starter
Hyperactive Member
Thanks you very much guys!!
Amon Ra
The Power of Learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|