 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Priya Mishra Guest
|
Posted: Wed Jun 28, 2006 9:10 am Post subject: this |
|
|
hi all,
Please any one help me out in understanding the "this" pointer in c++,
Please let me know the basic idea behind this, with very small
example.
I am not able to understand by the book language, I know C but some
what weak in C++
Thanks
Priya |
|
| Back to top |
|
 |
al pacino Guest
|
Posted: Wed Jun 28, 2006 9:10 am Post subject: Re: this |
|
|
if you 'know' java/python its analogous to 'self'....
or better still follow any good book on c++..chek out earlier topics on
'good' books on c++
Priya Mishra wrote:
| Quote: | hi all,
Please any one help me out in understanding the "this" pointer in c++,
Please let me know the basic idea behind this, with very small
example.
I am not able to understand by the book language, I know C but some
what weak in C++
Thanks
Priya |
|
|
| Back to top |
|
 |
al pacino Guest
|
Posted: Wed Jun 28, 2006 9:10 am Post subject: Re: this |
|
|
al pacino wrote:
| Quote: | if you 'know' java/python its analogous to 'self'....
or better still follow any good book on c++..chek out earlier topics on
'good' books on c++
Priya Mishra wrote:
hi all,
Please any one help me out in understanding the "this" pointer in c++,
Please let me know the basic idea behind this, with very small
example.
I am not able to understand by the book language, I know C but some
what weak in C++
Thanks
Priya
|
err sorry ppl top posted by mistake.... |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Wed Jun 28, 2006 9:10 am Post subject: Re: this |
|
|
* Priya Mishra:
| Quote: |
Please any one help me out in understanding the "this" pointer in c++,
Please let me know the basic idea behind this, with very small
example.
I am not able to understand by the book language, I know C but some
what weak in C++
|
Just ignore it.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
Jim Langston Guest
|
Posted: Wed Jun 28, 2006 9:10 am Post subject: Re: this |
|
|
"Priya Mishra" <mis.priya (AT) gmail (DOT) com> wrote in message
news:1151473208.211188.69380 (AT) j72g2000cwa (DOT) googlegroups.com...
| Quote: | hi all,
Please any one help me out in understanding the "this" pointer in c++,
Please let me know the basic idea behind this, with very small
example.
I am not able to understand by the book language, I know C but some
what weak in C++
Thanks
Priya
|
this simply points to the instance of the object that the method is being
called on. Usually it is not needed. Sometimes it is (such as to return a
pointer to itself). An example may illistrate.
#include <iostream>
#include <string>
class MyClass
{
public:
MyClass* GivePointer() { return this; }
};
void main()
{
MyClass* MyInstance = new MyClass();
MyClass* ObjectPointer = MyInstance->GivePointer();
if ( MyInstance == ObjectPointer )
std::cout << "Equal Pointers" << std::endl;
else
std::cout << "Not Equal Pointers" << std::endl;
std::string wait;
std::cin >> wait;
}
The output of this is:
Equal Pointers.
Again, usually you do not need to know the pointer of the instance you are
calling a method on. Sometimes you do though. If you don't need it, don't
worry about it. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|