C++primer 7.5.3 sessions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.