Member function pointers and high-performance
C ++ delegation (Part 1)
Member function pointers and the fastest possible C ++ delegates
Author:
Don Clugston
Translation: Zhou Xiang
Introduction
Standard
C ++ does not have a real
Abstract: This section describes how to obtain the member function address and call the address.
Keyword: C ++ member function this pointer call Convention
I. Usage of member function pointers
In C ++, the pointer to a member function is special.
The C language pointer is quite flexible, but it is also quite easy to make mistakes. Many C-language beginners, even the C-language veteran, are apt to stumble under the C-language pointer. But there is no denying that the position of the pointer
In C + +, a pointer to a member function is a very special thing. For a normal function pointer, it can be treated as an address and can be arbitrarily converted and called directly when needed. However, for member functions, general type
Http://blog.csdn.net/hairetz/article/details/4153252
First look at this piece of code
Class Test{Public:Test (int I) {m_ I = I ;}Test (){};Void Hello (){Printf ("Hello/N ");}PRIVATE:Int m_ I;};
Int main (){Test * P = new test ();P-> Hello ();P =
1. Replace the member function of the class with the non-member function of the class and the friend function as far as possibleFor example, a class to simulate human people
Copy Code code as follows:
1 class people{
2 Public:
3..
A member function is called as a thread function. A member function is called by a thread.Problems encountered
In programming, We Need To encapsulate data into a class. Calling pthread_create to create a thread using the member function is often
Reading Notes Objective c ++ Item 24 if all parameters of a function require type conversion, declare the function as a non-member function. objective is a non-member function.1. If you declare a function that requires implicit type conversion as a
In the coordinate class, there is a display () member function and a display () const member function with the following code
Class coordinate{public
:
coordinate (int x,int y);
void Display () const;
void Display ();
Private:
int m_ix;
4.4 Pointer to Member function (Pointer-to-member Functions)take a nonstatic data member address, the result is the member in the class layout of the byte position (plus 1), it is an incomplete value, need to be bound to the address of a class
Refer to the relevant chapter of "Pointer to a class member function", which includes the term "class member function", but strictly speaking, the member function here only refers to a non-static member function, this term also contains the term
4.4 Pointer to Member function (Pointer-to-member Functions)take a nonstatic data member address, the result is the member in the class layout of the byte position (plus 1), it is an incomplete value, need to be bound to the address of a class
C + + static member functions
Like a data member, a member function can also be defined as static, and the preceding addition of a function in a class becomes a static member function. Such as
static int volume ();
As with static
Member Function Templates is translated into Chinese as a Member Function template. I personally saw this in the source code of STL auto_ptr, and I didn't quite understand it at the time; over the past few days, I 've flipped through "More Effective
Item 45: Use member function templates (member function template) to accept "all compatible types" ("all compatible types ")
By Scott Meyers
Translator: fatalerror99 (itepub's nirvana)
Release: http://blog.csdn.net/fatalerror99/
Smart
The decision between Member and Non-memberThe binary Operators = (Assignment), [] (array subscription), -> (member access), as well as the N-ary () (fu Nction call) operator, must always be implemented as member functions, because the syntax of the
In C ++, member pointers are the most complex syntax structures. However, it is widely used in event-driven and multi-threaded applications to call-back functions. In multi-threaded applications, each thread calls this function by pointing to a
We know that in C + +, if a variable is declared as a const type, the operation that attempts to modify the value of the variable is considered a compilation error. For exampleConst Char blank='; blank='\ n'; // Error In object-oriented
First of all, I would like to thank bolow for his question raised in my blog [C ++ Basics] 028 _ getting pointers to class member functions. I have discussed with bolow and obtained the following answers.
First, let's look at the following program:
Difference 1:A static member function is actually a global function that does not depend on the object of a class. The static member function does not have the this pointer, but belongs to the class and does not create an object to call.The ordinary
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.