467,917 Members | 1,358 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,917 developers. It's quick & easy.

Why call member function through this pointer?

Why would someone call a non-static provate member function from
another non-static member function of the same class via the this
pointer?

Thanks.

DF

Jul 23 '05 #1
  • viewed: 2090
Share:
2 Replies
dm************@citigroup.com wrote:
Why would someone call a non-static provate member function from
another non-static member function of the same class via the this
pointer?


I hardly ever do, but perhaps some people use it to make more clear
difference between what is a call to member function and what is not.

For example in this example you could be easily fooled to think that the
program prints out "Function1()", unless you note that there is a member
function with a same name. With larger files with multiple different
functions, using "this->" would point out clearly that you are calling a
member function.
-----------------------------------
#include <iostream>

void Function1()
{
std::cout << "Function1()" << std::endl;
}

class ThisExample
{
private:
void Function1()
{
std::cout << "ThisExample->Function1()" << std::endl;
}

public:
void Test()
{
Function1();
}
};

int main()
{
ThisExample example;
example.Test();
return 0;
}
-----------------------------------
Jul 23 '05 #2
"Dmitry F" <Dmitry F@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Why would someone call a non-static provate member function from
another non-static member function of the same class via the this
pointer?


In the future, please to not multi-post. Instead, put each of the
intended newsgroups into the 'Newsgroups' header. That way,
replies are not duplicated and threads are not disjoint.

Your query has already been answered, redundantly, in at
least two of the newsgroups you multi-posted to.

Followups set accordingly.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Frederick Gotham | last post: by
12 posts views Thread by Rahul | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.