Skip to content

Commit ac99eba

Browse files
authored
Whitespace at cpp/pointers-to-members.md
Some sane whitespacing wouldn't hurt. Also, replaced "\n" with endl in cout.
1 parent d00b522 commit ac99eba

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

docs/cpp/pointers-to-members.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class Window
5555
public:
5656
Window(); // Default constructor.
5757
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.
6060
const char *GetCaption(); // Get window caption.
6161
char *szWinCaption; // Window caption.
6262
};
@@ -71,23 +71,24 @@ int main()
7171
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.
7272
7373
```cpp
74-
const char * (Window::*pfnwGC)() = &Window::GetCaption;
75-
bool (Window::*pfnwSC)( const char * ) = &Window::SetCaption;
74+
const char * (Window::* pfnwGC)() = &Window::GetCaption;
75+
bool (Window::* pfnwSC)( const char * ) = &Window::SetCaption;
7676
```
7777

7878
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`:
7979

8080
```cpp
81-
Window wMainWindow;
81+
Window wMainWindow;
8282
Window *pwChildWindow = new Window;
8383
char *szUntitled = "Untitled - ";
84-
int cUntitledLen = strlen( szUntitled );
84+
int cUntitledLen = strlen( szUntitled );
8585

8686
strcpy_s( wMainWindow.*pwCaption, cUntitledLen, szUntitled );
87-
(wMainWindow.*pwCaption)[cUntitledLen - 1] = '1'; //same as
88-
//wMainWindow.SzWinCaption [cUntitledLen - 1] = '1';
87+
(wMainWindow.*pwCaption)[cUntitledLen - 1] = '1'; // same as
88+
// wMainWindow.SzWinCaption [cUntitledLen - 1] = '1';
8989
strcpy_s( pwChildWindow->*pwCaption, cUntitledLen, szUntitled );
90-
(pwChildWindow->*pwCaption)[cUntitledLen - 1] = '2'; //same as //pwChildWindow->szWinCaption[cUntitledLen - 1] = '2';
90+
(pwChildWindow->*pwCaption)[cUntitledLen - 1] = '2'; // same as
91+
// pwChildWindow->szWinCaption[cUntitledLen - 1] = '2';
9192
```
9293
9394
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;
131132

132133
class Base
133134
{
134-
public:
135+
public:
135136
virtual void Print();
136137
};
137-
void (Base ::* bfnPrint)() = &Base :: Print;
138-
void Base :: Print()
138+
void (Base::* bfnPrint)() = &Base::Print;
139+
void Base::Print()
139140
{
140-
cout << "Print function for class Base\n";
141+
cout << "Print function for class Base" << endl;
141142
}
142143

143144
class Derived : public Base
144145
{
145-
public:
146+
public:
146147
void Print(); // Print is still a virtual function.
147148
};
148149

149-
void Derived :: Print()
150+
void Derived::Print()
150151
{
151-
cout << "Print function for class Derived\n";
152+
cout << "Print function for class Derived" << endl;
152153
}
153154

154155
int main()
@@ -162,6 +163,7 @@ int main()
162163
(bPtr->*bfnPrint)();
163164
}
164165

165-
//Output: Print function for class Base
166-
Print function for class Derived
166+
// Output:
167+
// Print function for class Base
168+
// Print function for class Derived
167169
```

0 commit comments

Comments
 (0)