frek wrote: |
---|
And then we can make use of the return value of the get() function to access the X class's members, yeah? So that "temporary" means we have no standalone object to use it for our tasks but using the return value of get, each time we need that accessibility, we use the members of the X class. Right? |
You can either use the returned object directly
or you can store it in a variable and then use it, possibly multiple times.
I'm probably making it sound more complicated than it really is. A "temporary" is an object that has no name and will live until the end of the full expression. It's pretty much the same as returning an integer.
|
int g() { return 15011; }
| |
The expression
15011
creates a temporary int which the function uses as its return value.
frek wrote: |
---|
Is it true for other non-int values too, for instance a char or string? |
Yes, but after being zero-initialized the string will be initialized by a constructor. If you don't explicitly initialize the string the default constructor will be used which initializes the string to an empty string.
All variables with
static storage duration (this includes all global variables, static data members and static local variables) will be zero-initialized this way, but I don't you need to worry too much about this zero-initialization stuff. Just initialize your non-class variables explicitly and you'll be fine.
jonnin wrote: |
---|
basic types will be zeroed (at the byte level, generally, note that 0x00000 etc is 0 for doubles and ints) |
Zero-initialization does not necessary mean the bit pattern will be all zeros. With GCC and Clang on Linux (not sure about other platforms) the null value for a
pointer to a data member will have the same bit pattern as -1 (all the bits set). It will nevertheless be set to null when zero-initialized, just like other pointers.
https://godbolt.org/z/3teRWA