tags: Effective C++
View C++ as a federation of languages.
- Efficient C ++ Programming Code, as the situation varies, depending on which part of your use of C ++.
Preper consts,enums and inlines to #defines.
- For simple constants, or preferably in const object enums replaced #defines.
- For the shape of a macro function (macros), preferably use the inline function replacement #defines.
Both can be used to define and const define a constant, but when const definition defines the type of constants, the more accurate number. #define simply text replacement, in addition to define constants, but can also be used to define some simple functions, somewhat similar to inline (Inline).
Use const whenever possible.
- Some things will be const help the compiler can detect errors usage. Const objects may be applied to any of scope, function arguments, return type of the function, the function of the body member.
- The compiler enforces bitwise constness, but you should use the "constants of the conceptual" (conceptual constness) when writing programs.
- When const and non-const member functions has achieved substantial equivalents, so that non-const version call the const version avoids code duplication.
const Usage:
const and pointers
int a = 5;
int * const p = & a; // pointer constant
const int * p = & a; // constant pointer
const reference
const reference point corresponding to the variable const const pointer, which points to the point, and the contents are allowed to change. So when the function returns a const reference, not by the function returns a reference to the actual object to make any changes.
const and function
1, const Return Value modification: a function call that can not be used as an expression value left.
2, const modified parameters: the parameter passed in the function can not be changed.
3, const function: Any attempt to change the member variables and call non-const member functions of operation are considered illegal.
const and class/
1, const initialization data member can only be performed in the initialization table constructor of the class;
2, const const object can only invoke a function as an ordinary function may modify a member variable. (Ordinary objects can either call the const function, you can also call ordinary function.)
Make sure that objects are initialized before they’re used.
- Manual initialization is built-in objects, because C ++ does not guarantee initialize them.
- Constructor is preferable to use the initial value column member (member initialization list), rather than using an assignment operator (Assignment) constructor body. The initial value of the member variable column lists, order over and they should be declared in the same order in class.
- For the removal of "cross-compilation unit of the initialization order" problem, replace the non-local static objects with local static objects.
Reference article:
《Effective C++》
C ++ usage at different locations in the const
C ++ inline functions (C ++ inline) Explanation
Quick arrival Every time you change your computer, the IDE is re-tossing, this record, I started ~ basis Font 2. Theme Every time you change your computer, the IDE is re-tossing, this record, I starte...
Terms 1: Visual C ++ is a language federal Four language parts of C ++:C, Object-oriented c++, template c++, STL please remember: C ++ efficient programming Code varies depending on the situation, dep...
First, build a LAMP environment ...
First look at the picture This is the big screen When this is a small screen This is when the small screen menu is expanded among them 1.Lang = “en” in The lang attribute written in...
Use image data to create a data format that can be input to Tensorflow Folder format: ROOT_FOLDER | ### Ideas: When we learn Tensorflow, we generally import mnist data directly. For the types of image...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using&nbs...
Header file my_func.h Source file my_func.cpp...
C # make your own packaging tool, the technology used is actually used in the C # inside"Dynamic Compilation"technology. The following simply describes the flow: 1. Your packaging tool has a...
Java: ...
Control flow If related Do not put variables andTrue False None () [] {}Direct comparison if foo == True: should be written as if foo: Check variables in the list But If not should be written in one l...