STILL IN Love With C ++ Chinese version (1)

zhaozj2021-02-08  261

STILL IN Love With C Chinese version (1)

[Posted: 2002-4-18 15:44:17]

Still in Love with C Chinese version of the Modern Language Features Enhance the Visual C .NET Compiler Author: Stanley B. Lippman Translator: Glory Abstract: Using C programmers have been for many years now in the midst of confusion: how to cater to their language C # And .NET coming? This article is taught about how C applies to the road sign of the .NET world. In .NET, C code can be used in two ways: managed and unmnaged. The uncontrolled code does not have CLR, while the controlled code is committed to using C controlled extensions. This article explains these two ways. Our people in our C communities feel that they are like a middle-aged child who has just come to a new baby. - Everyone is fanatically surrounded by this new little guy, (here,) even Someone gently took our head, we were lucky. It is difficult for us to have a feeling of being ignored and a little bit of harm. This is actually worse in technology, because the foundation is constantly drifting, and it is incorporated to survive. Of course, today's Microsoft .NET framework is new technology that is selling, how rich a big meal! Everyone is in the language called C #. If you are a C programmer, you can't doubt if you should learn C #, after all, in .NET discussion, if you take it with C # contrast, it is rare to mention C . Is the C programmer out of time? Absolutely not! In this article, I will introduce the new things in the current version of Visual Studio .Net, and give you some concept of Microsoft about C future plan. First, I will introduce two aspects of C in Visual Studio.NET: standard C and C are regulated. Maintaining compatibility is the main motivation behind standard C recently progress, that is, support support for ISO language characteristics. I will also discuss C controlled extensions, which makes C into a .NET language. Standard C standard compatibility in Visual Studio .NET has been made in the following field: l The virtual function definition now supports the cracked return type, which is a good news for those who write class hierarchies. l Static integer constant members can now be explicitly initialized. l Join the support of the MAIN to return 0. Below, I will briefly discuss each area. Join the Candarity Return Type is the first revision of the C language (approval by the Standard Commission). This is a wonderful-derived virtual function now returns an example of a derived class, and the virtual function in the base class it returns an instance of a base class. This is an important design idiom support for class hierarchies, and it is a popular "additive" in Visual Studio .NET. There is an example of a typical usage. Test abstract base class Query: class query {public: Virtual Query * Clone () = 0; // ...}; In the derived Class NOTQUERY instance, Clone returns a copy of a NotQuery object.

For example: class notquery // [Translation: This type of declaration is a bit problem] {public: virtual ???? Clone () {return new notquery (} // ... public: query * operand;}; No support for the Coordination Return, the return type of the NotQuery instance Clone must be query *: // no covariation return type support ... Virtual Query * Clone () {Return New NotQuery (this);} This will work Very good If you assign the return value of Clone to a query * pointer, just like this: NOTQUERY :: NOTQUERY (const notquery & rhs) {operand = rhs.Operand-> Clone ();} But this is not - when you want to show When it assigns it to a Notquery *, as follows: NOTQUERY NQ (New NameQuery); // [Translation: Less ")"]. // OOPS: illegal assignment ... NOTQUERY * PNQ0 = nq-> clone (); // ok: Need to convert ... NotQuery * pnq1 = static_cast (nq-> clone ()); With the support of the class back to the class, you can explicitly declare that NOTQUERY's Clone returns a NOTQUERY *: // has a Candle Return Type Support ... Virtual NotQuery * Clone () {Return New NotQuery (this);} This allows you to use Clone with intuitive way, without explicit modeling conversion: // ok: implicit conversion ... query * pq = nq-> clone (); // ok: no need to convert ... NOTQUERY * PNQ = NQ-> Clone (); although the explicit initialization of static integer constant members is not as important as the language characteristics such as Coordination Return type, it provides a majority in the case of a constant expression, it provides significant The design is convenient, such as an array definition used in fixed sizes. For example: class buffer {static const INT ms_buf_size = 1024; char m_buffer [ms_buf_size];}; static integer constant member is the only class member in C to be explicitly initialized in class definition, so that the value of the member can be Other ingredients in the class, such as the dimensions of the m_buffer. Otherwise, it is generally replaced by the enumeration as a symbol constant. Main return value represents the exit status of the program. The discussion, 0 indicates that the program successfully exited. For standard C , Main, there is no explicit return value means that the compiler will insert Return 0 before its tail. Visual C in Visual Studio .NET finally followed this standard. Controlled C Visual Studio .NET in Visual Studio .NET is mainly considered for the following three application strategies: l For uncontrolled APIs, it provides controlled .NET packaging classes, thus The existing C class is exposed to the Microsoft .NET platform. l You can use a Microsoft .NET class frame, and can be mixed with uncontrolled C .

There are three aspects for the framework: core language support, such as collection classes and system I / O; basic programming classes, such as support for threads, network sockets, and regular expressions; application domain support, such as XML, ASP.NET , Web Services, Windows Forms, and ADO.NET, etc. l You can write directly in the .NET environment, just like in C # and Visual Basic. However, this version of C has not yet provided support for RAD designers, such as Windows Forms and Web Forms. First, I will discuss packaging an unregulated implementation. In my "C Primer", I created a relatively large text query application, which focuses on the STL container class to parse text files and establish internal representation. Table 1 shows the included file, Table 2 shows the data representation. Table 1 Text Query Application Contains File #include #include #include #include #include #include #include #include #include #include using namespace std; Table 2 Data represents Typedef Pair location; typef vector Loc; typef vector text; typedef pair text_loc; class TextQuery {public: // ... private: vector * lines_of_text; text_loc * text_locations; map * word_map; Query * query; static string filt_elems; vector line_cnt }; Query is an abstract base class for interpreting an object-oriented hierarchy of query language. Table 3 shows a possible operation mode of a query session. A local call of text query system looks similar to: int main () {textQuery tq; tq.build_up_text (); tq.query_text ();} Table 3 Query session Enter a query-please separate Each Item BY a space.