mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
commit
97503abeaa
|
@ -3436,7 +3436,6 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
|
|||
|
||||
##### Example, bad
|
||||
|
||||
{
|
||||
int local = 42;
|
||||
|
||||
// Want a reference to local.
|
||||
|
@ -3444,17 +3443,14 @@ Pointers and references to locals shouldn't outlive their scope. Lambdas that ca
|
|||
// local no longer exists, therefore
|
||||
// process() call will have undefined behavior!
|
||||
thread_pool.queue_work([&]{ process(local); });
|
||||
}
|
||||
|
||||
##### Example, good
|
||||
|
||||
{
|
||||
int local = 42;
|
||||
// Want a copy of local.
|
||||
// Since a copy of local is made, it will be
|
||||
// available at all times for the call.
|
||||
thread_pool.queue_work([=]{ process(local); });
|
||||
}
|
||||
|
||||
##### Enforcement
|
||||
|
||||
|
@ -18865,11 +18861,11 @@ It is common to need an initial set of elements.
|
|||
|
||||
template<typename T> class Vector {
|
||||
public:
|
||||
vector<std::initializer_list<T>>;
|
||||
Vector(std::initializer_list<T>);
|
||||
// ...
|
||||
};
|
||||
|
||||
Vector<string> vs = { "Nygaard", "Ritchie" };
|
||||
Vector<string> vs { "Nygaard", "Ritchie" };
|
||||
|
||||
##### Enforcement
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user