effective-c++

What's the preferred sequence to read Effective, More Effective & Effective Modern C++ (and STL)? [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-20 14:42:33
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I understand that More Effective C++ is an expansion of Effective C++, while Effective Modern C++ focuses on C++11 & 14. Being a newbie to the language and just starting out with these books, should I read Effective Modern after the first two? Also, where should Effective STL

“Avoid returning handles to object internals”, so what's the alternative?

天大地大妈咪最大 提交于 2019-12-18 03:17:33
问题 Effective C++ by Scott Meyers tells in Chapter 5, Item 28 to avoid returning "handles" (pointers, references or iterators) to object internals and it definitely makes a good point. I.e. don't do this: class Family { public: Mother& GetMother() const; } because it destroys encapsulation and allows to alter private object members. Don't even do this: class Family { public: const Mother& GetMother() const; } because it can lead to "dangling handles", meaning that you keep a reference to a member

Returning local variables in C++ (Rule 21 in Effective C++, 3rd edition)

那年仲夏 提交于 2019-12-11 16:23:55
问题 As known, returning local variable from function in C++, is unsafe, due to scoping. In Effective C++ Third Edition, Scott Meyers tells about this problem in item 21, at page 101. However, in conclusion he said, that right decision will be to write: inline const Rational operator*(const Rational& lhs, const Rational& rhs) { return Rational(lhs.n * rhs.h, lhs.d * rhs.d); } Isn't this also a bad practice, and this function is unsafe? UPD: Thanks everybody for explanation. 回答1: You can't actually

Is effective C++ still effective?

﹥>﹥吖頭↗ 提交于 2019-12-04 07:24:09
问题 From what I saw in this post I decided to start reading the book Effective C++. But now that there are many new features because of C++11 and that a few of the good practices changed, I'm not sure whether or not it is actually a good idea. Has the advent of C++11 deprecated any of the advice contained in Effective C++? If so, which topics should I avoid? 回答1: This what Scott Meyers himself had to say about it on his own blog Which may lead you to wonder whether the information and advice in

Is it appropriate to set a value to a “const char *” in the header file

牧云@^-^@ 提交于 2019-12-03 11:37:59
问题 I have seen people using 2 methods to declare and define char * . Medhod 1: The header file has the below extern const char* COUNTRY_NAME_USA = "USA"; Medhod 2: The header file has the below declaration: extern const char* COUNTRY_NAME_USA; The cpp file has the below definition: extern const char* COUNTRY_NAME_USA = "USA"; Is method 1 wrong in some way ? What is the difference between the two ? I understand the difference between " const char * const var " , and " const char * var ". If in

Effective C++: discouraging protected inheritance?

試著忘記壹切 提交于 2019-12-03 08:30:07
问题 I was reading Scott Meyers' Effective C++ (third edition), and in a paragraph in Item 32: Make sure public inheritance is "is-a" on page 151 he makes the comment (which I've put in bold): This is true only for public inheritance. C++ will behave as I've described only if Student is publicly derived from Person. Private inheritance means something entirely different (see Item 39), and protected inheritance is something whose meaning eludes me to this day. The question : how should I interpret

What's the preferred sequence to read Effective, More Effective & Effective Modern C++ (and STL)? [closed]

点点圈 提交于 2019-12-03 03:39:33
I understand that More Effective C++ is an expansion of Effective C++, while Effective Modern C++ focuses on C++11 & 14. Being a newbie to the language and just starting out with these books, should I read Effective Modern after the first two? Also, where should Effective STL fit in? What is the preferred sequence to reading the above books, in the sense that each book is building on the content of the prior books? (Assuming everything inside is new to me?) Additionally, is Effective Modern C++ considered an unofficial next edition to Effective C++? An answer to this can be gleaned from the

Is effective C++ still effective?

早过忘川 提交于 2019-12-02 13:56:26
From what I saw in this post I decided to start reading the book Effective C++ . But now that there are many new features because of C++11 and that a few of the good practices changed, I'm not sure whether or not it is actually a good idea. Has the advent of C++11 deprecated any of the advice contained in Effective C++? If so, which topics should I avoid? This what Scott Meyers himself had to say about it on his own blog Which may lead you to wonder whether the information and advice in this pre-C++0x edition of Effective C++ remains relevant. I'm pleased to report that it does. Surprisingly

Function-like macros and strange behavior

泪湿孤枕 提交于 2019-12-01 22:42:39
I have started reading Effective C++ and at some point in item 2, the following is mentioned: // call f with the maximum of a and b #define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b)) ... int a = 5, b = 0; CALL_WITH_MAX(++a, b); // a is incremented twice CALL_WITH_MAX(++a, b+10); // a is incremented once Here, the number of times that a is incremented before calling f depends on what it is being compared with! Indeed, if I use a simple print statement in f , 7 gets printed in the first call, but I cannot for the life of me figure out why. Am I missing something obvious? The compiler replaces

Function-like macros and strange behavior

廉价感情. 提交于 2019-12-01 21:52:55
问题 I have started reading Effective C++ and at some point in item 2, the following is mentioned: // call f with the maximum of a and b #define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b)) ... int a = 5, b = 0; CALL_WITH_MAX(++a, b); // a is incremented twice CALL_WITH_MAX(++a, b+10); // a is incremented once Here, the number of times that a is incremented before calling f depends on what it is being compared with! Indeed, if I use a simple print statement in f , 7 gets printed in the first call,