You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp/pointers-to-members.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,8 +55,8 @@ class Window
55
55
public:
56
56
Window(); // Default constructor.
57
57
Window( int x1, int y1, // Constructor specifying
58
-
int x2, int y2 ); // window size.
59
-
bool SetCaption( const char *szTitle ); // Set window caption.
58
+
int x2, int y2 ); // Window size.
59
+
bool SetCaption( const char *szTitle ); // Set window caption.
60
60
const char *GetCaption(); // Get window caption.
61
61
char *szWinCaption; // Window caption.
62
62
};
@@ -71,23 +71,24 @@ int main()
71
71
In the preceding example, `pwCaption` is a pointer to any member of class `Window` that's of type `char*`. The type of `pwCaption` is `char * Window::*`. The next code fragment declares pointers to the `SetCaption` and `GetCaption` member functions.
The pointers `pfnwGC` and `pfnwSC` point to `GetCaption` and `SetCaption` of the `Window` class, respectively. The code copies information to the window caption directly using the pointer to member `pwCaption`:
The difference between the **`.*`** and **`->*`** operators (the pointer-to-member operators) is that the **`.*`** operator selects members given an object or object reference, while the **`->*`** operator selects members through a pointer. For more information about these operators, see [Expressions with Pointer-to-Member Operators](../cpp/pointer-to-member-operators-dot-star-and-star.md).
@@ -131,24 +132,24 @@ using namespace std;
131
132
132
133
classBase
133
134
{
134
-
public:
135
+
public:
135
136
virtual void Print();
136
137
};
137
-
void (Base::* bfnPrint)() = &Base :: Print;
138
-
void Base :: Print()
138
+
void (Base::* bfnPrint)() = &Base::Print;
139
+
voidBase::Print()
139
140
{
140
-
cout << "Print function for class Base\n";
141
+
cout << "Print function for class Base" << endl;
141
142
}
142
143
143
144
classDerived : publicBase
144
145
{
145
-
public:
146
+
public:
146
147
void Print(); // Print is still a virtual function.
147
148
};
148
149
149
-
void Derived :: Print()
150
+
voidDerived::Print()
150
151
{
151
-
cout << "Print function for class Derived\n";
152
+
cout << "Print function for class Derived" << endl;
0 commit comments