In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the compilation of C++ compilation and its code problem analysis". In the daily operation, I believe that many people have doubts about the compilation of C++ compilation and its code problem analysis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "C++ compilation and its code problem analysis". Next, please follow the editor to study!
If this is a design problem with the library you bought, there's nothing you can do about it (except for a better library), but you can organize your own code better to minimize the recompilation of modified code. Such designs are better and more maintainable because they show better conceptual separation.
Take a look at this typical object-oriented C++ compiler example:
Class Shape {public: / / the interface of the user using Shapes virtual void draw () const; virtual void rotate (int degrees); / /. Protected: / / common data (for implementers of Shapes) Point center; Color col; / /...}; class Circle: public Shape {public: void draw () const; void rotate (int) {} / /. Protected: int radius; / /...}; class Triangle: public Shape {public: void draw () const; void rotate (int); / /. Protected: Point a, b, c; / /...}
The idea is that users manipulate them through Shape's public interface, while the implementation parts of derived classes (such as Circle and Triangle) share the part of the implementation represented by protected members (implementation). This is not an easy task: determine which implementation parts are useful for all derived classes and share them.
As a result, protected members tend to make much more changes than the public interface. For example, although "center" is theoretically a valid concept for all graphics, it is very troublesome when you want to maintain the "center" of a triangle-for triangles, it makes sense to calculate the center if and only if it is really needed.
Protected members are likely to rely on the details of the implementation, while Shape users don't necessarily have to rely on them. Shape users don't necessarily have to rely on them. Protected members are likely to rely on the details of the implementation, but Shape users don't necessarily have to rely on them. For example, many (most? The code that uses Shape is logically independent of "color", but because of the definition of "color" in Shape, it may require a bunch of complex header files to incorporate the color concept of the operating system.
When the protected part changes, the code that uses Shape must be recompiled-- even if only the implementation part of the derived class can access the protected member. As a result, the "implementation-related information" (information helpful to implementers) in the base class becomes as sensitive to the user as an interface, and its existence leads to instability of the implementation part, unnecessary recompilation of the user code (when the implementation part changes), and uncontrolled inclusion of header files into the user code (because they are needed for "implementation-related information"). This is sometimes called the "fragile base class problem" (brittle base class problem).
An obvious solution is to ignore the "implementation-related information" in the base class that is used like an interface. In other words, use interfaces, pure interfaces. That is, the interface is represented as an abstract base class:
Class Shape {public: / / the interface of the user using Shapes virtual void draw () const = 0; virtual void rotate (int degrees) = 0; virtual Point center () const = 0; / /... / / No data}; class Circle: public Shape {public: void draw () const Void rotate (int) {} Point center () const {return center;} / /. Protected: Point cent; Color col; int radius; / /...}; class Triangle: public Shape {public: void draw () const; void rotate (int); Point center () const; / /. Protected: Color col; Point a, b, c; / /.}
Now, the relationship between the user's compilation of C++ and the changes in the implementation of the derived class is isolated. I have seen this technique reduce compilation time by several orders of magnitude.
At this point, the study of "C++ compilation and its code problem analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.