Effective C++ | 00 Introduction
Effective C++ | 00 Introduction
Book: Effective C++ (Third Edition)
TERMINOLOGY
-
Declaration
Tells compilers about the name and type of something but omits details -
Definition
Provides compilers with the details a declaration omits -
Initialization
Process of giving an object its first value
Constructors declared explicit USE!
Prevents them from being used to perform implicit type conversions
Copy constructor
Used to initialize an object with a different object of the same type
Copy assignment Operator
Used to copy the value from one object to another of the same type
Widget w1; // invoke default constructor
Widget w2(w1); // invoke copy constructor
w1 = w2; // invoke copy
// assignment operator
If an object is being defined (Widget w3) a (copy) constructor has to be called
It can’t be an assignment
If no new object is being defined (w1 = w2) no constructor, so assignment
Copy constructor defines how an object is passed by value
Pass-by-value means “call the copy constructor”
Function objects
Objects that act like functions
Such objects come from classes that overload operator()
the function call operator
Undefined behavior
Behavior of some constructs in C++ is literally not defined: can’t reliably predict runtime
examples:
// access violation
int* p = 0;
cout << *p;
报错:

Naming Conventions
lhs: left-hand-side
rhs:right-hand-side
Used as parameter names for functions implementing binary operators
e.g.
operator==
operator*
a * b
operator*(a,b)
Non-member functions
const Rational operator*(const Rational& lhs, const Rational& rhs);
Member functions
lhs represented by the this pointer
Threads
C++ as a language has no notion of threads, concurrency, STL
C++ is concerned, multithreaded programs do NOT exist
TR1: Technical Report1
Specification for new functionality added to C++ standard library
New class and function templates
Hash tables, reference-counting smart pointers, regular expressions
tr1 namespace nested in std namespace
Boost
Offers portable, peer-reviewed, open source C++ libraries
TR1 functionality based on Boost but Boost offers more
EffectiveC++:深入解析构造与赋值
文章介绍了C++中的关键概念,如声明与定义的区别,构造函数与复制构造函数的作用,以及复制赋值运算符的功能。强调了显式构造函数的使用,防止隐式类型转换,并提到了未定义行为的风险。此外,讨论了命名约定在二元操作符实现中的应用,以及C++对线程和并发的支持情况,包括TR1和Boost库的角色。
220

被折叠的 条评论
为什么被折叠?



