|
-
June 18th, 2002, 09:30 PM
#1
Where are "this" pointers are assigned ?
As we all know, in C++, this means a pointer to
the object itself. But where and when is the pointer
created?
I have try the follwing cod:
class A{
A(){ cout<<"A::A() is called."; }
A(int a){ A(); cout<<"A:A(int a) is called"; };
~A(){ cout<<"A is destructing ...";}
}
main(){
A a;
return 0;
}
it shows that in the constructor A::A(int),
another tempory object of A is created.
Then the question is rasied:
Where and when is this be assigned,
at the beginning or at the end of the constructor?
Last edited by Lacura; June 18th, 2002 at 09:34 PM.
Every day is a new day.
-
June 18th, 2002, 11:49 PM
#2
Hi Lacura,
'this' is not created and not assigned.
Every time You instantiate class, first thing is being done -allocating memory block.
Then start address of the memory block is implicitly passed to every non-static
member function (to constructor like to every other n. static member function)
So, 'this' is the keyword, associated with hidden parameter.
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
|