C++ 杂记

144 阅读1分钟

C++ is a multiparadigm programming language, one supporting a combination of procedural, object-oriented, functional, generic and metaprogramming features  

C++ isn’t a unified language with a single set of rules; it’s a federation of four sublanguages, each with its own conventions 

            C

            Object-Oriented C++ 

            Template C++ 

            The STL

 

Prefer consts, enums, and inlines to #defines

            #define may be treated as if it is not part of the language per se

            #define ASPECT__RATIO 1.653 (wrong)

            Const double AspectRatio = 1.653; (right)

 

 

To define a constant char*-based string in a header file, you have to write const twice:

            Const char* const authorName = “Scott Meyers”;

            But, string objects are generally preferable to their char*based progenitors:

                        Const std::string authorName(“Scott Meyers”)

 

 

Class-specific constants

            Usually C++ requires that you provide a definition for anything you use, but class-specific constants that are static and of integral type are an exception 

            Class GamePlayer{

            Private:

                        Static const int NumTurns =5;  // constant declaration

                        Int scores[NumTurns];            // use of constant 

            };