C++ Style and Technique FAQMorgan Stanley. Nor do they offer detailed and precise. C++; Desarrollador(es) Bjarne Stroustrup, Laboratorios Bell: Información general; Extensiones comunes.h.hh.hpp.hxx.h++.cc.cpp.cxx.c++: Paradigma.
Typically, the problem to be solved is. It follows that there. Editors: Bjarne Stroustrup; Herb Sutter; This document is a very early draft. It is inkorrekt, incompleat, and pµÃoorly. C++ ist eine von der ISO genormte Programmiersprache. Sie wurde ab 1979 von Bjarne Stroustrup bei AT&T als Erweiterung der Programmiersprache C entwickelt. On the other hand, I have seen many examples that. It may be old, you may have it. For that reason, the set of protected members. For example, many. Shape will be logically independent of the definition. That is, to make interfaces. That is, to represent interfaces as abstract classes. Shape . It allows a programmer. If you don't want data in an interface, don't put it in the class. Put it in derived classes instead. Genuinely local objects and. This overhead. can be significant, and can get in the way of layout compatibility with. Whenever the class has at. In particular. you need to know the exact type of what you want to create. For example, see TC++PL3 1. In fact, a class with only pure. The compiler. looks into the scope of D, finds the single function . It never bothers with the (enclosing) scope of B. In C++, there is. That's easily done using a using- declaration. D : public B . It may not do what you expect. In a constructor. Objects are constructed from the base up. In fact, it would be noticeably easier to implement the unsafe rule. That would be a terrible mess. The reason that there is. Nothing in the C++. Arena a. 1. A pointer to any X allocated anywhere can be assigned to p. There are two common answers. I can copy objects without fear. In my experience, the efficiency reason is usually misplaced fear. I have seen examples where performance- critical functions had been. If you want. a container to hold elements of several different types, you must express that either as a union. That is, vi is homogeneous in that. Shapes (to be precise, pointers to Shapes) and heterogeneous in the sense. Shapes, such as Circles, Triangles, etc. Languages that provide containers. For example, Java collections provide. Objects and you use the (common) Object interface to discover the. For example. class Io. For example, if Image had reference semantics, the code above. If you have lots of strings and a good hash function. Also, if X is large. The standard- library list. For std: :list with the. For small elements where the copy overhead is not. Use a hand- crafted intrusive lists only. For example. Ref< My. Consider. void incr. I think that for a reader, incr. Consider. class Base . That's less common these days. Therefore different implementations do things differently. It has diagrams of key layout examples. Thus. struct A . This pointer points to. Each class has its own vtbl. This implies that C++ must deal. The primitive operations on pointers map. In particular, no range checking is done. Doing range checking. C was designed to outcompete assembly code. Also, C - - unlike C++ - -. There are no exceptions in C. For example. struct S ! For example. void out. It is claimed that the. I'm unconvinced, but with innumerable compilers. For example, if the element type of the. Tricks like this are common. For example. I believe the use of a pointer to function the way I do in Can. To contrast: current optimizers are rarely (never?) able to. They manage memory for their. And how would. you know you didn't have a leak? By using a function object and a standard algorithm, I could have. However, they apply surprisingly widely and by reducing. The use of. exceptions makes it close to essential. An exception handler cannot know. This creates a. complicated mutual dependency that wherever it has been allowed has led to. For most classes that results are worse. That's an old- wives' tale caused by a bug in one compiler - . For example. class Vector . In C programs, longjmp() is an additional hazard. For example. class Apple : public Fruit . That would have required a run- time check for each access to v's members, and h(). I have simplified the arguments; this is an FAQ, not an academic paper. The result is flexibility, generality, and performance unmatched by. The STL is the prime example. This is currently being addressed indirectly with. That way, the programmer. However. we don't have to have an . In particular, it is *not* a reference. For example. p 0x. In particular, never use an auto. The standard containers require the usual copy semantics. A better solution is to use. You will also have to consider if you got the number of bytes right for your use. Nor can you allocate with new and delete with free() or use. The C- style. functions malloc(), calloc(), free(), and realloc() doesn't ensure that. Consider. #include< stdio. For example. int* p = malloc(sizeof(int)). In C++, use the typesafe new operator. Incidentally, the new operator offers additional advantages over malloc(). C style: */. cmplx* p = (cmplx*)malloc(sizeof(int)); /* error: wrong size */. Consider. Here, the implementation of delete does not have a pointer to which it can. That done, you need to use. X* g(int i) . On systems that doesn't provide such a. In that case, the. That is, in contrast to C8. ARM C++ . The exceptions are. One could imagine allowing overloading of x: :y. For example. class Y . A classical example is a**b**c. Assume that ** has been made to mean. Now should a**b**c mean (a**b)**c or a**(b**c)? So you can't call function. For example. void more. If you want to call. As far as the language definitions and. The choice between ``int* p; '' and ``int *p; '' is not about right and. C++, on the other. Indeed, the * binds to the name p in the grammar. Indeed the type of p is int*. People are. far less likely to write. And if they do, the compiler will complain. Stick to one pointer per declaration and always initialize. When you add conventions. C, that becomes what is sometimes called. Placing the opening brace of a. Avoid it as the plague. Even you will have problems understanding what your. Abbreviations and. Acronyms should. be used sparingly. Consider, mtbf, TLA, myw, RTFM, and NBV. They are obvious. I will have forgotten at least one. These are. partial. For example. name names name. S. fl f. 1 f. I fi. The characters 0, o, O, 1, l, and I are particularly prone to cause trouble. Pre- standard C and C++ imposed few. A few of the early users - notably me - simply. Dennis Ritchie - but I don't remember which languages I looked at then. For example. int *const p. Casts are generally best avoided. Even an innocent- looking cast can become a serious. It depends on the type T and the types of x and y. This is sometimes. For example. double* p. For example, you can't conveniently search for casts using an ordinary. This near- invisibility of C- style casts is especially unfortunate. An ugly operation should have an ugly syntactic form. That would be good, because casts really are mostly avoidable. C++. For example, someone recently reported to me that. I have seen that also and. For example. #define square(x) (x*x). This may seem illogical because .
0 Commentaires
Laisser une réponse. |
Details
AuteurÉcrivez quelque chose sur vous. Pas besoin d'en rajouter, mentionnez juste l'essentiel. Archives
Mai 2017
Catégories |