TAILIEUCHUNG - Expert C++/CLI .NET for Visual C++ Programmers phần 4

Để đảm bảo rằng sự mơ hồ ít nhất là phát hiện khi các phiên bản tiếp theo của các lớp học có nguồn gốc được xây dựng, trình biên dịch phát ra cảnh báo cấp độ 4. Bạn có thể sử dụng từ khoá mới để thể hiện rằng bạn nhận thức được rằng bạn đã xác định một chức năng không liên quan có cùng tên và chữ ký trong các lớp cơ sở. | CHAPTER 5 DEFINING MANAGED TYPES 91 To make sure that the ambiguity is at least detected when the next version of the derived class is built the compiler emits a level 4 warning. You can use the keyword new to express that you are aware that you have defined an unrelated function with the same name and signature as in the base class. This avoids the ambiguity warning. ref class Derived public Base public void g new Virtual Functions Extending a base class with virtual functions can cause even more problems. Some of these problems are in the nature of public inheritance other problems exist because the C syntax for virtual functions leaves room for ambiguities. The following code shows an ambiguity that exists in C code class Derived public Base public void f If you see just this class declaration you cannot say whether the function f is a virtual function or not. If Base defines or inherits a virtual function f with the same and signature as Derived f then Derived f overrides this virtual function and therefore Derived f is a virtual function too. This is sometimes called implicit overriding. When overriding a virtual function in C the keyword virtual is optional Derived f overrides Base f without explicitly stating this. To make clear that Derived f is a virtual function you could define the function with the keyword virtual. However in this case it would not be clear whether Derived overrides Base f or introduces a new virtual function f. C CLI introduces a new syntax for the declaration of virtual functions. This syntax is mandatory for virtual functions of managed types. If you compile with clr or clr pure you can also use this syntax for native classes. The new syntax is called explicit overriding. This means that the keyword virtual is no longer optional whenever you declare a virtual function you have to use the keyword virtual. This also means that the lack of this keyword is a sure indicator that the function is not virtual. In addition to the keyword .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.