By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,127 Members | 1,366 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,127 IT Pros & Developers. It's quick & easy.

Why call member function through this pointer?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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.