Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reflective information in classes

Status
Not open for further replies.

bob54

Programmer
Oct 26, 2002
3
GB
Say I have a class foo, and that one of its fields is a pointer to an instance of itself:

class foo
{

int x;

foo y;


}

When the constructor for foo is called, I want it to initialize the value of the y field to the instance of foo that just got constructed.

foo()
{
y=THIS INSTANCE OF foo just now constructed
}

I'm not sure how to do this. Any suggestions?

 
Don't know why (or y) you would want to do this since the instance already has implicit access to itself but the solution is:
Code:
y = this;
Again, this makes no sense. Explain the reasoning behind wanting to do this and we will be able to help you with a solution to your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top