Hello all and thanks in advance for reading!
I have been playing around with classes and now want to dive in the 'this' keyword. I have been looking over the internet and I cannot get a good description of exactly what it does. So here are a few of my questions...
If I have a the following (syntax maybe wrong)
Code:
class x
{
public :
int a;
int b;
int c;
int d;
int setIntegers(int a, int b, int c, int d)
};
int x::setIntegers(int a, int b, int c, int d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
return(this);
}
What exactly gets returned by this. Also lets say instead of return(this) I have another class that has function addAll() and I call the following:
Code:
//Instead of return(this) within setIntegers function
y->addAll(this);
y::addAll()
{
z = a+b+c+d;
//return(z);
//NOTE: This will not return anything, it will only store z as a private int.
}
First is that syntax right with the pointer? And secondly what would the parameters need to be for the addAll function.
Also am I calling the function correctly? By calling returning the this does it properly send out all of the varaibles...
Furthermore ( I know long post sorry ><; )
lets say within class x I have the following code instead...
Code:
x::setIntegers(int a, int b, int c, int d)
{
this->a = a;
this->b = b;
this->c = c;
this->d = d;
}
x::processVariables()
{
y->addAll(this);
//This is linking into the code snippet above.
}
Would it do the exact same thing yet now the values are set and can be sent at any request?
I hope all of my questions are clear and if need be I can elaborate. Thank you all again!
**EIDT**
I should also mention that this is not code I am working on but for example purposes. I believe understanding this example for me should be enough to help me accomplish my primary goal.