Skip to content

Mark code as cpp style #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions docs/cpp/function-overloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You can overload both member functions and non-member functions. The following t
## Example
The following example illustrates how overloading can be used.

```
```cpp
// function_overloading.cpp
// compile with: /EHsc
#include <iostream>
Expand Down Expand Up @@ -135,7 +135,7 @@ int print(double dvalue, int prec)

Consider the following declarations (the functions are marked `Variant 1`, `Variant 2`, and `Variant 3`, for identification in the following discussion):

```
```cpp
Fraction &Add( Fraction &f, long l ); // Variant 1
Fraction &Add( long l, Fraction &f ); // Variant 2
Fraction &Add( Fraction &f, Fraction &f ); // Variant 3
Expand All @@ -145,7 +145,7 @@ Fraction F1, F2;

Consider the following statement:

```
```cpp
F1 = Add( F2, 23 );
```

Expand All @@ -160,7 +160,7 @@ F1 = Add( F2, 23 );

The intersection of these two sets is Variant 1. An example of an ambiguous function call is:

```
```cpp
F1 = Add( 3, 6 );
```

Expand All @@ -186,7 +186,7 @@ F1 = Add( 3, 6 );

However, the function overloading mechanism can distinguish between references that are qualified by **const** and `volatile` and references to the base type. This makes code such as the following possible:

```
```cpp
// argument_type_differences.cpp
// compile with: /EHsc /W3
// C4521 expected
Expand Down Expand Up @@ -296,7 +296,7 @@ Multiple-Inheritance Graph Illustrating Preferred Conversions

User-defined conversions are applied if no built-in promotion or conversion exists. These conversions are selected on the basis of the type of the argument being matched. Consider the following code:

```
```cpp
// argument_matching1.cpp
class UDC
{
Expand Down Expand Up @@ -324,7 +324,7 @@ int main()

During the process of matching arguments, standard conversions can be applied to both the argument and the result of a user-defined conversion. Therefore, the following code works:

```
```cpp
void LogToFile( long l );
...
UDC udc;
Expand All @@ -335,7 +335,7 @@ LogToFile( udc );

If any user-defined conversions are required to match an argument, the standard conversions are not used when evaluating the best match. This is true even if more than one candidate function requires a user-defined conversion; in such a case, the functions are considered equal. For example:

```
```cpp
// argument_matching2.cpp
// C2668 expected
class UDC1
Expand Down Expand Up @@ -381,7 +381,7 @@ int main()

The `.` member-selection operator works exactly the same way, except that an implicit `&` (address-of) operator is prefixed to the object name. The following example shows how this works:

```
```cpp
// Expression encountered in code
obj.name

Expand Down Expand Up @@ -447,7 +447,7 @@ int main()

- `typedef` declarations do not define new types; they introduce synonyms for existing types. They do not affect the overloading mechanism. Consider the following code:

```
```cpp
typedef char * PSTR;

void Print( char *szToPrint );
Expand All @@ -460,14 +460,14 @@ int main()

- The types "array of " and "pointer to" are considered identical for the purposes of distinguishing between overloaded functions. This is true only for singly dimensioned arrays. Therefore, the following overloaded functions conflict and generate an error message:

```
```cpp
void Print( char *szToPrint );
void Print( char szToPrint[] );
```

For multiply dimensioned arrays, the second and all succeeding dimensions are considered part of the type. Therefore, they are used in distinguishing between overloaded functions:

```
```cpp
void Print( char szToPrint[] );
void Print( char szToPrint[][7] );
void Print( char szToPrint[][9][42] );
Expand All @@ -483,7 +483,7 @@ If the base class function is not declared as 'virtual', then the derived class

Block scope is strictly observed; therefore, a function declared in file scope is not in the same scope as a function declared locally. If a locally declared function has the same name as a function declared in file scope, the locally declared function hides the file-scoped function instead of causing overloading. For example:

```
```cpp
// declaration_matching1.cpp
// compile with: /EHsc
#include <iostream>
Expand Down Expand Up @@ -517,7 +517,7 @@ int main()

Note that the call to `Deposit` in `Account::Deposit` calls the private member function. This call is correct because `Account::Deposit` is a member function and therefore has access to the private members of the class.

```
```cpp
// declaration_matching2.cpp
class Account
{
Expand Down Expand Up @@ -565,4 +565,4 @@ double Account::Deposit( double dAmount, char *szPassword )


## See Also
[Functions (C++)](../cpp/functions-cpp.md)
[Functions (C++)](../cpp/functions-cpp.md)