Hi,

Derek's question about copying SparseMatrix led me to google about
ways to automatically keep constructors up-to-date with class members.
 I didn't really find anything about that, but in doing so I came
across one of google's coding style guidelines:

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Copy_Constructors

"Provide a copy constructor and assignment operator only when
necessary. Otherwise, disable them with DISALLOW_COPY_AND_ASSIGN."

So apparently they have some macro to declare copy constructor and op=
private when they are not needed.  At first I thought this was
overkill because I assumed that if you provided *any* constructor, the
compiler doesn't auto-generate the copy constructor or operator=, but
that is wrong.  If you ever provide an empty constructor for your
class, the copy ctor and op= still get auto-generated...


// Class D has a user-defined, non-empty constructor which takes a
// (dummy) argument, *and* an empty constructor.  This does *not*
// prevent auto-generation of other functions
class D
{
public:
  D() { }
  D(int) { }
};


int main()
{
  D d1;
  D d2(d1); // auto-generated
  d1 = d2; // auto-generated
  return 0;
}



So... I'm wondering if we should do something similar (disable op= and
copy ctor unless needed and explicitly provided, possibly with a
macro) in all of our library classes?  A cursory examination already
revealed some weird stuff:

1.) BoundaryInfo op= implemented but copy ctor not?  If you


2.) class LinearSolver has an empty constructor but no copy
constructors declared/disabled.  It also has a pointer to a
Preconditioner object, so a LinearSolver was copied, a shallow copy of
the Preconditioner pointer would be made.

3.) DofObject has a public copy constructor but no operator= defined
(so probably has an auto-generated op=) and it contains pointer data

4.) PeriodicBoundaries has empty ctor and therefore auto-generated op=
and copy ctor.  It doesn't contain any additional pointer data though
so it's probably OK... for now.


-- 
John

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Libmesh-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libmesh-devel

Reply via email to