3 ms·
In C++ block is often a way to ensure automatic variable destruction. This is important, because in C++ often there is important stuff going on in destructor. F
by ajuc 15y ago
In C++ block is often a way to ensure automatic variable destruction. This is important, because in C++ often there is important stuff going on in destructor. For example in RAII idiom.
Example:
...
...
{ //critical section
QMutexLocker locksInConstructorAndUnlocksInDestructor(&mutex);
a = doStuff(a,b,c);
b = doOtherStuff(a,b,c);
c = andAnother(a,b,c);
}
..
..
It would be overkill to make this block a function, especially when code in critical section changes many variables.
- scott_s 15y agoThis is an accepted idiom in C++, but I don't think it makes much sense in Java, since there are no destructors.