Hi Yuesu, I think this is rather a general C++ question. Once you create an object all members are initialized by invoking a constructor. If you do not declare any constructor the compiler will silently generate a set of constructors. The default constructor that takes no arguments is one of them. This will initialize all members in the order they are given. If you have a member of a primitive type like double or int memory for an int or double will be reserved (but not initialized with a value yet). If you have a class member it also needs to be initialized somehow so the compiler will look for a default constructor.
What happens in your example is that the triangulation actually does get initialized by invoking its default constructor which initializes an empty triangulation. The dof_handler then can be called with the triangulation as an argument to store a (smart) pointer to the triangulation. See this documentation for example: https://docs.microsoft.com/en-us/cpp/cpp/constructors-cpp?view=vs-2019#constructors_in_composite_classes It is often good to know what the C++ compiler (secretly) does without explicitly telling you and what functions it generates if you do not provide them explicitly (and when you must do so). I really recommend the book by Scott Meyers "Effective C++: 55 ways ..." Hope that helps. Best, Konrad On Wednesday, September 4, 2019 at 4:44:24 AM UTC+2, yuesu jin wrote: > > Hi all, > > I have a question about the constructor initialization list. In some > tutorials, we initialize the dof_handler in the constructor with parameter > triangulation, however, the triangulation is initialized in some member > function within this class, which means when we initialize the class, we > have not had the triangulation yet, I don't know why this method works? > > Best regards, > Yuesu > -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/fd3807d1-51e6-4daa-8eed-5da2eec1336b%40googlegroups.com.
