Why call member function through this pointer?

D

dmitry.freitor

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
 
A

Aggro

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;
}
-----------------------------------
 
L

Larry Brasfield

Dmitry F said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top