C ++ is an advanced C language version. Of course, it has all the functions of C language. To some extent, it also has many practical application functions. Today, we will introduce pointer operations and specific application methods of C ++ pointer overloading.
Example code of C ++ pointer overloading:
- # Include "stdafx. h"
- # Include <iostream>
- # Include <string>
- Template <typename T>
- Inline T const & max (T const & a, T const & B)
- {
- Return a <B? B:;
- }
- // Evaluate the iterator of the two pointer values
- Template <typename T>
- Inline T const & max (T * const & a, T * const & B)
- {
- Return * a <* B? * B: *;
- }
- // Evaluate the referers of two strings
- Inline char const * const & max (char const * const &,
Char const * const & B)
- {
- Return strcmp (a, B) <0? B:;
- }
- Int _ tmain (int argc, _ TCHAR * argv [])
- {
- // Compare the maximum values of two int values. The first max template is called.
- Int a = 7;
- Int B = 42;
- Std: cout <"max (a, B) =>" <: max (a, B) <std: endl;
- // Compare the maximum values of two strings. The first max template is called.
- Std: string s = "hey ";
- Std: string t = "you ";
- Std: cout <"max (s, t) =>" <: max (s, t) <std: endl;
- // Compare the maximum value of the two pointers. The second max template is called.
- Int * p1 = &;
- Int * p2 = & B;
- Std: cout <"max (p1, p2) =>" <: max (p1, p2) <std: endl;
- // Compare the maximum values of two c strings. The third non-template max function is called.
- Char const * s1 = "David ";
- Char const * s2 = "Nico ";
- Std: cout <"max (s1, s2) =>" <: max (s1, s2) <std: endl;
- Return 0;
- }
- Analysis on Application Methods of C ++ object Replication
- Analysis of basic implementation methods of C ++ Using Interfaces
- Analysis of the similarities and differences between the left and right values of C ++
- C ++ template parameters
- C ++ template function reloads different comments
Note the following when reloading the above C ++ pointer code:
1): max (a, B) and max (s, t) call the same max template function. Because they satisfy the definition of the first template function, they only have different types.
2): max (p1, p2) calls are somewhat mysterious.
3): max (s1, s2) calls the third non-template max function. The second template function is not used to generate new instances.