C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

this

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Priya Mishra
Guest





PostPosted: Wed Jun 28, 2006 9:10 am    Post subject: this Reply with 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





PostPosted: Wed Jun 28, 2006 9:10 am    Post subject: Re: this Reply with 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:
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





PostPosted: Wed Jun 28, 2006 9:10 am    Post subject: Re: this Reply with quote



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





PostPosted: Wed Jun 28, 2006 9:10 am    Post subject: Re: this Reply with quote

* 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





PostPosted: Wed Jun 28, 2006 9:10 am    Post subject: Re: this Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.