Re: [deal.II] Required mapping member initialization of type MappingQ
Dear Wolfgang, thanks for clearing this up and responding so fast. Your explanation makes sense to me. Best Konrad Wolfgang Bangerth schrieb am Mittwoch, 8. März 2023 um 15:03:13 UTC+1: > On 3/8/23 06:34, Konrad Schneider wrote: > > > > Only if I uncomment line 30 of my code (// , mapping(mapping_degree)) > the > > program compiles. Why is that? In my understanding, the program should > compile > > just fine without the initialization of the mapping member variable > since > > there is no requirement of initializing member variables upon > constructing an > > object, is would be the case for my member variable unsigned int test. > > This isn't true. In a constructor, *all* member variables [1] are > initialized > by calling their constructors. If you explicitly list a member in the > initializer list (after the ':'), then the constructor arguments so > specified > are taken. If you don't explicitly list a variable, then the default > constructor of the variable's class is called. But the latter only works > if > the class *has* a default constructor. It turns out that MappingQ does > not: > The only constructor there is requires you to provide the polynomial > degree. > As a consequence, the compiler cannot do a default-initialization, and you > are > forced to explicitly list the variable in the initializer list. > > Best > W. > > > [1] This is not quite true: all *class type* member variables are > initialized, > whereas variables of built-in types like int, double, etc are not unless > you > explicitly initialize them. > > -- > > Wolfgang Bangerth email: bang...@colostate.edu > www: http://www.math.colostate.edu/~bangerth/ > > > -- 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 dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/8a6d8887-dd98-4945-9325-f51731f10e3dn%40googlegroups.com.
Re: [deal.II] Required mapping member initialization of type MappingQ
On 3/8/23 06:34, Konrad Schneider wrote: Only if I uncomment line 30 of my code (// , mapping(mapping_degree)) the program compiles. Why is that? In my understanding, the program should compile just fine without the initialization of the mapping member variable since there is no requirement of initializing member variables upon constructing an object, is would be the case for my member variable unsigned int test. This isn't true. In a constructor, *all* member variables [1] are initialized by calling their constructors. If you explicitly list a member in the initializer list (after the ':'), then the constructor arguments so specified are taken. If you don't explicitly list a variable, then the default constructor of the variable's class is called. But the latter only works if the class *has* a default constructor. It turns out that MappingQ does not: The only constructor there is requires you to provide the polynomial degree. As a consequence, the compiler cannot do a default-initialization, and you are forced to explicitly list the variable in the initializer list. Best W. [1] This is not quite true: all *class type* member variables are initialized, whereas variables of built-in types like int, double, etc are not unless you explicitly initialize them. -- Wolfgang Bangerth email: bange...@colostate.edu www: http://www.math.colostate.edu/~bangerth/ -- 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 dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/d4469b8b-200b-6a30-6ded-7416515cfa23%40colostate.edu.
[deal.II] Required mapping member initialization of type MappingQ
Dear all, I am fairly new to deal.ii and have a question concerning the MappingQ-class of deal.ii Why do I have to initialize the private mapping member of type MappingQ to get a compilable code? To illustrated what I mean, I did thin out the step-11 tutorial in the following way: #include #include #include #include #include #include using namespace dealii; template class LaplaceProblem{ public: LaplaceProblem(const unsigned int mapping_degree, const unsigned int fe_degree=1); void run(); private: Triangulation triangulation; const unsigned int fe_degree; FE_Q fe; DoFHandler dof_handler; MappingQ mapping; unsigned int test; }; template LaplaceProblem::LaplaceProblem(const unsigned int mapping_degree, const unsigned int fe_degree) : fe_degree(fe_degree) , fe(fe_degree) , dof_handler(triangulation) // , mapping(mapping_degree) { } template void LaplaceProblem::run(){ } int main(){ const unsigned int mapping_degree=2; LaplaceProblem<2>(mapping_degree).run(); } Only if I uncomment line 30 of my code (// , mapping(mapping_degree)) the program compiles. Why is that? In my understanding, the program should compile just fine without the initialization of the mapping member variable since there is no requirement of initializing member variables upon constructing an object, is would be the case for my member variable unsigned int test . I would be grateful for any explanation. Many thanks in advance. -- 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 dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/92911e1a-8ca1-425f-a859-9b5a6e877b4dn%40googlegroups.com.