Exercise 7.43
Answers on the web
1#include <iostream>2 usingstd::cout;3 usingStd::endl;4 5 classNoDefault6 {7 Public:8NoDefault (inti)9 {Tenval =i; One } A intVal; - }; - the classC - { - Public: - nodefault nd; +Cinti =0): nd (i) {} - }; + A intMain () at { - c C; -cout<<c.nd.val<<Endl; - return 0; -}
But it feels wrong, for such a constructor is not the default constructor of C, just the constructor of C. The default constructor for C cannot be constructed without the NoDefault default constructor being considered by the individual;
Exercise 7.44
is not legal because the NoDefault class does not have his default constructor, so the definition will eventually be undefined.
Exercise 7.45
If C can construct a default constructor, it is legal and vice versa. (But I think the default constructor for C cannot be constructed.)
Exercise 7.46
A error, because if the class does not provide any one constructor, the compiler provides a composite default constructor when it is required;
b Error, if the constructor provides default arguments for all parameters, then he actually defines the default constructor;
C Error, the default constructor is theoretically necessary;
D error, if the class contains a member of a built-in type or composite type, the class should not rely on the composition's default constructor.
C++primer 7.5.3 sessions