QSettings().setValue( DEST_FOLDER, destDir );
will give you a default constructed temporary instance of QSettings
that will exist until the end of the full expression, in this case the ;
at the end of the line, and then call setValue(...)
on said temporary.
You can call every constructor you want this way, not just the default constuctor as you did in your example. If e.g. class A
has a constructor and a member function fun
that take a single int
,
A(5).fun(20);
will create a temporary object of type A
via A::int(5)
and then call A::fun(int i)
with i = 20
on it.
This is allowed and safe, whether this actually makes sense depends on what the method you call does in the end.
Note that the class itself is neither nameless nor temporary, only the instance you create is.
2
solved Creating a temporary nameless class instance in C++