Analysis of the actual operation code of the C ++ custom class

Source: Internet
Author: User

The application methods of C ++ programming language are flexible. You can select the appropriate application methods based on your own needs to complete various functions. Today we will introduce some practical operations of the C ++ custom class, hoping to help you.

 
 
  1. //// // TestClass. h ///////////////////
  2. Class TestClass
  3. {
  4. Public:
  5. Void Test ();
  6. Int;
  7. Private:
  8. Int B;
  9. Public:
  10. Static int c;
  11. // Do not forget to include this Semicolon. Otherwise, the following cpp will prompt the error message indicating that the semicolon is missing in namespace.
  12. /// // C ++ BaseTest. cpp ////////////////////////
  13. # Include "stdafx. h"
  14. # Include "TestClass. h"
  15. # Include <iostream>
  16. Using namespace std;
  17. TestClass tc;
  18. // Tc. a = 10;
  19. // Tc. B = 30;
    // You will find that an error is reported when initializing TestClass member variables as global variables.
  20. Int TestClass: c = 8;
    // Static variable of the class, which does not need to be added before the definition; otherwise, an error is reported. It is the shared value of all class objects.
  21. Void TestClass: Test ()
  22. {
  23. B = 20;
  24. Cout <a <"" <B <"" <c <endl;
  25. }
  26. Int _ tmain (int argc, _ TCHAR * argv [])
  27. {
  28. Tc. a = 10; // The member variables of the class object are correct during local initialization. The member variables of the object belong to the object.
  29. // For example, you have assigned a value to Member a of the tc object,
    In the following Test function, the value of a is a member of the tc of the object.
  30. Cout <tc. a <endl;
  31. Tc. Test ();
  32. While (true)
  33. {
  34. }
  35. Return 0;
  36. }

The specific operation methods of the C ++ custom class are described here.

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.