So the conclusion is that for a class that has a default constructor, there is absolutely no difference. But I would be more comfortable if the () were included.
-- Anders 20 aug 2012 kl. 23:38 skrev Benjamin Kehlet <benja...@simula.no>: > 2012/8/20 Anders Logg <l...@simula.no>: >> On Mon, Aug 20, 2012 at 05:00:32PM +0100, Garth N. Wells wrote: >>> On 20 August 2012 16:50, Anders Logg <l...@simula.no> wrote: >>>> I'm editing the linear algebra interface to add support for generic >>>> Krylov matrices and I'm seeing things like this: >>>> >>>> >>>> /// Create empty vector (global) >>>> boost::shared_ptr<GenericVector> create_vector() const >>>> { >>>> boost::shared_ptr<GenericVector> x(new MTL4Vector); >>>> return x; >>>> } >>>> >>>> /// Create empty vector (local)o >>>> boost::shared_ptr<GenericVector> create_local_vector() const >>>> { >>>> boost::shared_ptr<GenericVector> x(new MTL4Vector); >>>> return x; >>>> } >>>> >>>> I thought () was required: >>>> >>>> boost::shared_ptr<GenericVector> x(new MTL4Vector()); >>>> >>>> Has this always been the case? >>>> >>> >>> There are some instances where we need to distinguish between local >>> and distributed vectors, notably in the PETSc interface code. To work >>> through GenericVector, it appears in the MTL, uBLAS, etc code too. >> >> I know, I wasn't referring to the global vs local. I meant omitting >> the () in constructors that take no arguments: >> >> new MTL4Vector() >> >> vs >> >> new MTL4Vector > > Cases exist where the behaviour will be different, but they are rare. > > Compare > http://en.cppreference.com/w/cpp/language/default_initialization > with > http://en.cppreference.com/w/cpp/language/value_initialization > > (Some examples are given in this answer: http://stackoverflow.com/a/620402 ) > > Benjamin > >> >> -- >> Anders >> >> _______________________________________________ >> Mailing list: https://launchpad.net/~dolfin >> Post to : dolfin@lists.launchpad.net >> Unsubscribe : https://launchpad.net/~dolfin >> More help : https://help.launchpad.net/ListHelp _______________________________________________ Mailing list: https://launchpad.net/~dolfin Post to : dolfin@lists.launchpad.net Unsubscribe : https://launchpad.net/~dolfin More help : https://help.launchpad.net/ListHelp