mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-18 21:24:41 +03:00
updating gh-pages
This commit is contained in:
@@ -6889,7 +6889,7 @@ And we could extend the hierarchies by adding a Smiley class (:-)):
|
||||
// ...
|
||||
};
|
||||
|
||||
class Impl::Smiley : Public Smiley, public Impl::Circle { // implementation
|
||||
class Impl::Smiley : public Smiley, public Impl::Circle { // implementation
|
||||
public:
|
||||
// constructors, destructor
|
||||
// ...
|
||||
@@ -10691,7 +10691,7 @@ Requires messy cast-and-macro-laden code to get working right.
|
||||
|
||||
void error(int severity)
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
std::cerr << '\n';
|
||||
std::exit(severity);
|
||||
}
|
||||
|
||||
@@ -12665,10 +12665,10 @@ Using `unsigned` doesn't actually eliminate the possibility of negative values.
|
||||
|
||||
##### Example
|
||||
|
||||
unsigned int u1 = -2; // OK: the value of u1 is 4294967294
|
||||
unsigned int u1 = -2; // Valid: the value of u1 is 4294967294
|
||||
int i1 = -2;
|
||||
unsigned int u2 = i1; // OK: the value of u2 is 4294967294
|
||||
int i2 = u2; // OK: the value of i2 is -2
|
||||
unsigned int u2 = i1; // Valid: the value of u2 is 4294967294
|
||||
int i2 = u2; // Valid: the value of i2 is -2
|
||||
|
||||
These problems with such (perfectly legal) constructs are hard to spot in real code and are the source of many real-world errors.
|
||||
Consider:
|
||||
@@ -13287,7 +13287,7 @@ Local static variables are a common source of data races.
|
||||
// ...
|
||||
auto h1 = async([&]{ sort(par, s); }); // spawn a task to sort
|
||||
// ...
|
||||
auto h2 = async([&]{ return find_all(buf, sz, pat); }); // span a task to find matches
|
||||
auto h2 = async([&]{ return find_all(buf, sz, pat); }); // spawn a task to find matches
|
||||
// ...
|
||||
}
|
||||
|
||||
@@ -14708,8 +14708,8 @@ Not all member functions can be called.
|
||||
// if elem != nullptr then elem points to sz doubles
|
||||
public:
|
||||
Vector() : elem{nullptr}, sz{0}{}
|
||||
Vector(int s) : elem{new double}, sz{s} { /* initialize elements */ }
|
||||
~Vector() { delete elem; }
|
||||
Vector(int s) : elem{new double[s]}, sz{s} { /* initialize elements */ }
|
||||
~Vector() { delete [] elem; }
|
||||
double& operator[](int s) { return elem[s]; }
|
||||
// ...
|
||||
private:
|
||||
@@ -18487,7 +18487,7 @@ Because, obviously, breaking this rule can lead to undefined behavior, memory co
|
||||
##### Note
|
||||
|
||||
This is a semi-philosophical meta-rule, which needs many supporting concrete rules.
|
||||
We need it as a umbrella for the more specific rules.
|
||||
We need it as an umbrella for the more specific rules.
|
||||
|
||||
Summary of more specific rules:
|
||||
|
||||
@@ -20674,16 +20674,16 @@ Here is an example of the last option:
|
||||
class B {
|
||||
protected:
|
||||
B() { /* ... */ }
|
||||
virtual void PostInitialize() // called right after construction
|
||||
virtual void post_initialize() // called right after construction
|
||||
{ /* ... */ f(); /* ... */ } // GOOD: virtual dispatch is safe
|
||||
public:
|
||||
virtual void f() = 0;
|
||||
|
||||
template<class T>
|
||||
static shared_ptr<T> Create() // interface for creating objects
|
||||
static shared_ptr<T> create() // interface for creating objects
|
||||
{
|
||||
auto p = make_shared<T>();
|
||||
p->PostInitialize();
|
||||
p->post_initialize();
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user