I dunno, maybe this would do what you are trying, but I haven't compiled to double check.
Code:
&Pointless Pointless::ReturnSelf() {
return &this;
}
Code:
int main() {
Pointless a;
Pointless *b;
b = a.ReturnSelf();
As Quantum stated:
the this keyword should return the caller that you are attempting to do.
------------------------------------------------------------------------------------------
This section is if you are trying to make a copy, which I am unsure if this is what your intention ultimately is. So you can ignore this part if it doesn't help you.
Note in your example:
Code:
int main() {
Pointless a;
Pointless *b;
b = &a.ReturnSelf(); // Is this even valid expression? -,-.
If this code works, which it might if you replace Self with the this pointer it still won't make a copy of a and store it in b, rather it just makes b point to a. So any changes to one will also be made to the other. b & a are now essentially one object b a.k.a. a.
If you want a true copy you need a copy constructor like someone else mentioned.
Code:
// Note this is a public funtion in Pointless Class.
void Pointless::Operator=(Pointless pIn)
{
this.x = pIn.x;
}
Code:
int main()
{
Pointless a, b;
b = a;
}
Something like this. Look up overloading the = operator or just use the word copy instead like:
Code:
// Note this is a public funtion in Pointless Class.
void Pointless::copy(Pointless pIn)
{
this.x = pIn.x;
}
Code:
int main()
{
Pointless a, b;
b.copy(a);
}
P.S. Some of my code may not compile correctly, but the principles should be correct.
Hope some, if any, of this helped.
----------------------------------------------
By the way, how do you guys have signatures on your posts? I didn't see a sig. option anywhere. Is it because I haven't posted enough yet?