C Language Reference Manual_4
Số trang: 26
Loại file: pdf
Dung lượng: 298.02 KB
Lượt xem: 11
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Quá tải độ phân giải độ phân giải quá tải là một cơ chế để lựa chọn các thành viên chức năng tốt nhất để gọi cho một danh sách đối số và thiết lập một thành viên chức năng ứng cử viên. Tình trạng quá tải giải quyết lựa chọn thành viên chức năng để gọi trong các bối cảnh khác biệt sau đây trong C #:
Nội dung trích xuất từ tài liệu:
C Language Reference Manual_4 Chapter 7 Expressions class Test { static void F(ref object x) {...} static void Main() { object[] a = new object[10]; object[] b = new string[10]; F(ref a[0]); // Ok F(ref b[1]); // ArrayTypeMismatchException } }the second invocation of F causes an ArrayTypeMismatchException to be thrown because the actualelement type of b is string and not object.7.4.2 Overload resolutionOverload resolution is a mechanism for selecting the best function member to invoke given an argument list anda set of candidate function members. Overload resolution selects the function member to invoke in the followingdistinct contexts within C#:• Invocation of a method named in an invocation-expression (§7.5.5).• Invocation of a constructor named in an object-creation-expression (§7.5.10.1).• Invocation of an indexer accessor through an element-access (§7.5.6).• Invocation of a predefined or user-defined operator referenced in an expression (§7.2.3 and §7.2.4).Each of these contexts defines the set of candidate function members and the list of arguments in its own uniqueway. However, once the candidate function members and the argument list have been identified, the selection ofthe best function member is the same in all cases:• First, the set of candidate function members is reduced to those function members that are applicable with respect to the given argument list (§7.4.2.1). If this reduced set is empty, an error occurs.• Then, given the set of applicable candidate function members, the best function member in that set is located. If the set contains only one function member, then that function member is the best function member. Otherwise, the best function member is the one function member that is better than all other function members with respect to the given argument list, provided that each function member is compared to all other function members using the rules in §7.4.2.2. If there is not exactly one function member that is better than all other function members, then the function member invocation is ambiguous and an error occurs.The following sections define the exact meanings of the terms applicable function member and better functionmember.7.4.2.1 Applicable function memb erA function member is said to be an applicable function member with respect to an argument list A when all ofthe following are true:• The number of arguments in A is identical to the number of parameters in the function member declaration.• For each argument in A, the parameter passing mode of the argument is identical to the parameter passing mode of the corresponding parameter, and • for an input parameter, an implicit conversion (§6.1) exists from the type of the argument to the type of the corresponding parameter, orCopyright Microsoft Corporation 1999-2000. All Rights Reserved. 93C# LANGUAGE REFERENCE • for a ref or out parameter, the type of the argument is identical to the type of the corresponding parameter.7.4.2.2 Better function memberGiven an argument list A with a set of argument types A1, A2, ..., AN and two applicable function members MP andMQ with parameter types P1, P2, ..., PN and Q1, Q2, ..., QN, MP is defined to be a better function member than MQ if• for each argument, the implicit conversion from AX to PX is not worse than the implicit conversion from AX to QX, and• for at least one argument, the conversion from AX to PX is better than the conversion from AX to QX.7.4.2.3 Better conversionGiven an implicit conversion C1 that converts from a type S to a type T1, and an implicit conversion C2 thatconverts from a type S to a type T2, the better conversion of the two conversions is determined as follows:• If T1 and T2 are the same type, neither conversion is better.• If S is T1, C1 is the better conversion.• If S is T2, C2 is the better conversion.• If an implicit conversion from T1 to T2 exists, and no implicit conversion from T2 to T1 exists, C1 is the better conversion.• If an implicit conversion from T2 to T1 exists, and no implicit conversion from T1 to T2 exists, C2 is the better conversion.• If T1 is sbyte and T2 is byte, ushort, uint, or ulong, C1 is the better conversion.• If T2 is sbyte and T1 is byte, ushort, uint, or ulong, C2 is the better conversion.• If T1 is short and T2 is ushort, uint, or ulong, C1 is the better conversion.• If T2 is short and T1 is ushort, uint, or ulong, C2 is the better conversion.• If T1 is int and T2 is uint, or ulong, C1 is the better ...
Nội dung trích xuất từ tài liệu:
C Language Reference Manual_4 Chapter 7 Expressions class Test { static void F(ref object x) {...} static void Main() { object[] a = new object[10]; object[] b = new string[10]; F(ref a[0]); // Ok F(ref b[1]); // ArrayTypeMismatchException } }the second invocation of F causes an ArrayTypeMismatchException to be thrown because the actualelement type of b is string and not object.7.4.2 Overload resolutionOverload resolution is a mechanism for selecting the best function member to invoke given an argument list anda set of candidate function members. Overload resolution selects the function member to invoke in the followingdistinct contexts within C#:• Invocation of a method named in an invocation-expression (§7.5.5).• Invocation of a constructor named in an object-creation-expression (§7.5.10.1).• Invocation of an indexer accessor through an element-access (§7.5.6).• Invocation of a predefined or user-defined operator referenced in an expression (§7.2.3 and §7.2.4).Each of these contexts defines the set of candidate function members and the list of arguments in its own uniqueway. However, once the candidate function members and the argument list have been identified, the selection ofthe best function member is the same in all cases:• First, the set of candidate function members is reduced to those function members that are applicable with respect to the given argument list (§7.4.2.1). If this reduced set is empty, an error occurs.• Then, given the set of applicable candidate function members, the best function member in that set is located. If the set contains only one function member, then that function member is the best function member. Otherwise, the best function member is the one function member that is better than all other function members with respect to the given argument list, provided that each function member is compared to all other function members using the rules in §7.4.2.2. If there is not exactly one function member that is better than all other function members, then the function member invocation is ambiguous and an error occurs.The following sections define the exact meanings of the terms applicable function member and better functionmember.7.4.2.1 Applicable function memb erA function member is said to be an applicable function member with respect to an argument list A when all ofthe following are true:• The number of arguments in A is identical to the number of parameters in the function member declaration.• For each argument in A, the parameter passing mode of the argument is identical to the parameter passing mode of the corresponding parameter, and • for an input parameter, an implicit conversion (§6.1) exists from the type of the argument to the type of the corresponding parameter, orCopyright Microsoft Corporation 1999-2000. All Rights Reserved. 93C# LANGUAGE REFERENCE • for a ref or out parameter, the type of the argument is identical to the type of the corresponding parameter.7.4.2.2 Better function memberGiven an argument list A with a set of argument types A1, A2, ..., AN and two applicable function members MP andMQ with parameter types P1, P2, ..., PN and Q1, Q2, ..., QN, MP is defined to be a better function member than MQ if• for each argument, the implicit conversion from AX to PX is not worse than the implicit conversion from AX to QX, and• for at least one argument, the conversion from AX to PX is better than the conversion from AX to QX.7.4.2.3 Better conversionGiven an implicit conversion C1 that converts from a type S to a type T1, and an implicit conversion C2 thatconverts from a type S to a type T2, the better conversion of the two conversions is determined as follows:• If T1 and T2 are the same type, neither conversion is better.• If S is T1, C1 is the better conversion.• If S is T2, C2 is the better conversion.• If an implicit conversion from T1 to T2 exists, and no implicit conversion from T2 to T1 exists, C1 is the better conversion.• If an implicit conversion from T2 to T1 exists, and no implicit conversion from T1 to T2 exists, C2 is the better conversion.• If T1 is sbyte and T2 is byte, ushort, uint, or ulong, C1 is the better conversion.• If T2 is sbyte and T1 is byte, ushort, uint, or ulong, C2 is the better conversion.• If T1 is short and T2 is ushort, uint, or ulong, C1 is the better conversion.• If T2 is short and T1 is ushort, uint, or ulong, C2 is the better conversion.• If T1 is int and T2 is uint, or ulong, C1 is the better ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính tài liệu công nghệ thông tin lập trình máy tính mẹo máy tính cài đặt máy tínhGợi ý tài liệu liên quan:
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 317 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 305 0 0 -
Thêm chức năng hữu dụng cho menu chuột phải trên Windows
4 trang 290 0 0 -
70 trang 251 1 0
-
Bài giảng Tin học lớp 11 bài 1: Giới thiệu ngôn ngữ lập trình C#
15 trang 238 0 0 -
Tổng hợp lỗi Win 8 và cách sửa
3 trang 233 0 0 -
Sửa lỗi các chức năng quan trọng của Win với ReEnable 2.0 Portable Edition
5 trang 214 0 0 -
Giáo trình Bảo trì hệ thống và cài đặt phần mềm
68 trang 208 0 0 -
Tổng hợp 30 lỗi thương gặp cho những bạn mới sử dụng máy tính
9 trang 205 0 0 -
UltraISO chương trình ghi đĩa, tạo ổ đĩa ảo nhỏ gọn
10 trang 204 0 0