Embed Python into the operator overloading of C ++. If you overload related operators in C ++. when Python is passed to Python, You can overload the "+" operator of the Msg class by using the following code. def (self + self) "is passed to Python.
Why reload operators?1. Make the class behave like the built-in data type
2. More control over Program Performance
Restrictions on Operator Overloading
1. New operators cannot be added.
2. Some operators cannot be overloaded.
3. The
Why do we need conversion operators? We all know that we can use forced conversion characters to convert data of built-in types, for example, (int) 2.1f; custom classes are also types, therefore, the custom class objects also need to support this
1. Conditional operators (? :), Also known as the ternary (object) operator, is a simplified form of the if... else structure and can be nested for use. [Csharp] int x = 1; string s = x + ""; s + = (x = 1? "Man": "men"); Console. writeLine (s); //
Priority level
Operator
Name or meaning
Use form
Combination direction
Description
1
[]
Array subscript
array name [constant expression]
Left to right
()
Parentheses
A. String Insertion
To provide maximum flexibility for developers to handle string values, PHP provides a literal insert and content insertion
A method.
Double quotation marks provide maximum flexibility because both the variable and the transfer
Operator Overloading is the ability to allow users to write expressions using user-defined types.
For example
Code To add two numbers. Obviously, sum is the sum of two numbers.
Int I = 5;
Int sum = I + J;
If you can use a user-defined type that
I recently read "C language basics and Application Instances" and found interesting ++ operators. Let's take a look at the results of the following statements.
1
//
What is the result? Guys :)
Main ()
{IntI=3;Printf ("% D, % d, % d \
1. Nullable type modifier (? ):A reference type can use a null reference to represent a value that does not exist, and a value type usually cannot be represented as empty. For example: string str=null; is correct, int i=null; the compiler will error.
Operator function: operator
Operator Overloading:
A. Become a member function
B. namespace functions (youyuan functions)
The following operators cannot be overloaded :::,.,.*,? :
Operators that must be reloaded as member functions: [], (),->,
Q: How do I distinguish the prefix and Postfix formats when operators are overloaded?
(Note: It turns out that this is the term "more effective C ++" when I read a book at night. "M6 really doesn't work if I don't read a book ...)
Answer: In the
?? It may be a forgotten operator, which is rarely used. Its usage is simple but practical:
Variable ?? Defaultvalue
Equivalent
Variable = NULL? Defaultvalue: Variable
With it, a row can handle lazy evaluation:
Use ?? Before:
Code highlighting
Operator overloadI. meaning and definition of operator overloading
L The existing operators of C ++ are only suitable for processing the basic data types of C ++.
L c ++ allows you to redefine existing operators (Operator overloading) so that it can
Precedence
Operator
Description
Example
Associativity
1
()[]->.::++--
Grouping OperatorArray accessMember access from a pointerMember access from an objectScoping OperatorPost-IncrementPost-Decrement
(A + B)/4;Array [4]
Operator Overloading is a tool used in class definition. The following is an example of adding or subtracting a complex number. The operation between two classes is achieved by reloading "+, that is, the addition and subtraction of two class objects;
Priority
Operator
Description
Example
Associativity
1
()[]->.::++--
Parentheses operator for priority adjustmentArray subscript access operatorAccess the member operator by pointing to the object pointerOperator for
1. Use of priority OperatorsI believe that all people who have played C have had such or such incredible experiences, and they will feel very deeply profound and profound about C, most of the time, you do not know the actual execution of a statement
Guidance:Types of operators C-language operators can be divided into the following types:1. Arithmetic OperatorsIt is used for various numerical operations. Including addition (+), subtraction (-), multiplication (*), Division (/), remainder (or
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.