I have this snippet of code which seems to work well:
class foo{/* some member variables and functions*/};
void do_somthing(foo x={}){}
int main(){
do_somthing();
}
I used to use void do_somthing(foo x=foo()){}
to default the x
argument but I see this way ={}
in some book or online example(can not remember). Is it totally ok to use it? Is there any difference between the two methods?
foo x=foo()
is copy initialization,and
foo()
is value initialization.foo x={}
is aggregate initialization.So the result is the same in this case (both value-initialized).
And the effects of value initialization in this case are:
Finally the effects of zero initialization in this case are: