A:
From
http://stackoverflow.com/questions/9181782/why-are-the-terms-automatic-and-dynamic-preferred-over-the-terms-stack-and
Automatic tells me something about the lifetime of an object: specifically that it is bound automatically to the enclosing scope, and will be destroyed automatically when that scope exits.
Dynamic tells me that the lifetime of an object is not controlled automatically by the compiler, but is under my direct control. |
Example:
1 2 3 4
|
int * foo() {
int * bar = new int;
return bar;
}
|
The bar is a pointer and an automatic variable. It is destroyed/deallocated at the end of the function.
Line 2 allocates memory dynamically for one integer. The address of that memory is stored in bar. The memory remains allocated after the end of foo().
The foo() returns a pointer. Caller of foo can assign the value to a pointer variable. Value of bar can thus be kept evenm though bar is destroyed. Copying the memory address around is critical , because without it the dynamically addressed cannot be referred any more, not deallocated.
See
http://msdn.microsoft.com/en-us/library/hh438473.aspx
2:
http://en.wikipedia.org/wiki/Subtyping
http://www.cplusplus.com/doc/tutorial/polymorphism/
3:
http://qt-project.org/doc/qt-5/qstring.html#toUInt
1 2 3 4
|
QString str = "42";
bool ok;
uint hex = str.toUInt(&ok);
uint foo = str.toUInt();
|
Call on line 3 gives the toUInt an address of a bool. The function uses the given memory location to store true/false.
Call on line 4 gives 0 as address. There is no place to write to, so the function does not even attempt to write true/false.
In other words storing of the conversion success info is optional and the caller decides whether to do it.
One could write overloads:
1 2
|
uint QString::toUInt();
uint QString::toUInt(bool&);
|
However, that is a lot of code duplication for such a tiny optional feature.