Weekly lab report (I)

Source: Internet
Author: User
01. # include <iostream> 02. using namespace STD; 03. class C 04. {05. PRIVATE: 06. int X; 07. public: 08. C (int x) {This-> X = x;} 09. int getx () {return x ;}10 .}; 11. 12. void main () 13. {14. C (5); // change the originalProgramRemove const in 15. cout <C. getx (); 16. system ("pause"); 17 .} 18. 19. 20. // The second solution is as follows 21. 22. # include <iostream> 23. using namespace STD; 24. class C 25. {26. PRIVATE: 27. int X; 28. public: 29. C (int x) {This-> X = x;} 30. int getx () 31. const {return X;} // a regular object can only access the regular function 32 .}; 33. 34. void main () 35. {36. const C (5); 37. cout <C. getx (); 38. system ("pause"); 39 .}

Related Article

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.