473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
2 2383
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
3
by: zx.zhangxiong | last post by:
Dear all, I'm puzzled about the usage of class member function. Any help would be appreciated. class Account { ...
8
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
20
by: Bruce. | last post by:
I am trying to call a member function through a pointer to it and can't get the syntax exactly right. This compiles with an error C2064, term does not evaluate to a function taking 1 argument.. ...
3
by: zaeminkr | last post by:
I have class member data which is a pointer to class member function. However, I'm fail to compile the code. What is the correct grammar to make a function call by using static member data...
3
by: Pawel_Iks | last post by:
I have following class definition (A.h file): class A { public: int N; int count1(int n) {n++;} int count2(int n) {n+=5;} int otherFun(int n, int (*fun)(int)); }
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.