Why i can't return this?

Hello everyone! I create a class and inside it a make a function which is refered to the specific class. Inside the specific function i make use of "*this" and i have a problem.Forgive me if i am lisened a litle naive but i haven't much experience of "this" pointer yet.Take a look:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class one
{
	public:
		int a,b;
		one(int l,int k){a=l;b=k;}
		one& kalamari(one tsiou);


	private:
};

one& one::kalamari(one tsiou)
{
	a+=tsiou.a;
	b+=tsiou.b;
        cout<<"this-->"<<*this.a<<endl;//Here is my question


	return *this;
}


(Corect me if i am wrong)Since "this" is a pointer which is refering to the element one i thought i could use it to return only one part of this element,thus :

cout<<"this-->"<<*this.a<<endl;//Here is my question

But my compiler returns me an error, Why i can't do that?Is there anything you can suggest? Thanks for your time.
I'm having trouble understanding what you're trying to say. What are you trying to do at line 16?

Also, at line 19, are you sure you have enough asterisks there?

-Albatross
You should write a or (*this).a or this->a.
The element access (.) operator has higher priority than the dereferencing operator (*).
Thank you all for your time,thanks Athar now i understood what i was doing wrong. May i ask you something more?

Can i return only one part of the element?
for example:
1
2
3
4
5
6
7
8
one& one::kalamari(one tsiou)
{
    a+=tsiou.a;
    b+=tsiou.b;


    return (*this).a;
}
Topic archived. No new replies allowed.