Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of C++ programming skills

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "C++ programming skills example Analysis". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In C++, the Sort method in the Windows class becomes the basic method of the Sort method in the ListBox class, and when the Sort method in the Windows class is expected to be called, the Sort method in the ListBox class is called. In C #, virtual functions are always considered to be the root of virtual scheduling. That is, once C# finds a virtual method, it will not look for other virtual methods in the virtual chain. If ListBox is compiled again, the compiler generates a warning message:

"class1.cs (54 Window.Sort 24): warning CS0114: 'ListBox.Sort ()' hides inherited member 'Window.Sort ()'.

To make the current member override the original method, you need to add an override keyword or a new keyword. To eliminate warnings, the programmer must figure out what he wants. You can add new before the Sort method in the ListBox class, indicating that it should not override the virtual method in Window:

Public class ListBox: Window {public new virtual void Sort () {"}

This clears the warning message. If programmers do expect to override methods in Window, they must use the override keyword to explicitly indicate their intention.

Employee::Employee (int theAge, int theSalaryLevel): Person (theAge) / / initialize the base class salaryLevel (theSalaryLevel) / / initialize the member variable {/ / constructor code}

Initialization in C# is different from that in C++. Suppose you have a Person class with a member variable of private nature, age, and Employee is generated by continuing the Person class, which has a salaryLevel member variable of private nature. In C++, we can initialize salaryLevel in the initialization part of Employee's constructor, as shown in the following code:

Class Employee: definition of public Person {/ / member variables private salaryLevel = 3; / / initialization}

This method is illegal in C #. Although the underlying class can still be initialized, initializing member variables like the above code causes compilation errors. In C #, we can initialize a member variable while defining it. Note that access to each variable must be clearly defined.

This is the end of the content of "C++ programming skills example Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report