This section describes C ++ classes and C # classes.

Source: Internet
Author: User

Many programmers have learned C ++ and concluded that C ++ is an independent language rather than a C language, you can directly learn C ++ without starting with C. I hope you can learn what you want here.

The "C" language series is the best example of the development of object-oriented design. C ++ provides developers with excellent object-oriented programming tools. programmers can explicitly create constructors, copy constructors, overload operators, and Use templates.

The main problem with complex languages such as C ++ is that it takes several months for programmers to master the nature of object-oriented design. New programmers must learn how to master templates, function overloading, and, of course, create and use classes with good functions.
Microsoft has given C # (read as C-Sharp) Some object-oriented nature to C ++.

  • About the formatting of floating point numbers in C ++
  • Introduction to C/C ++
  • Build a Carbide C ++ Development Platform
  • How to better learn C ++
  • Introduction to Visual C ++ 6.0 Compiler Learning

For example, the template, but changed the class creation method. In this article, I will compare the C ++ classes and focus on the changes in class creation and usage of Microsoft in C. The object of this article is a skilled C ++ programmer who explains the essence of C # object-oriented through some details.

As you know, C # is partly based on C ++ and partly based on Java syntax. In C #, there are some changes in details so that they can be used in modern design. When you start to use C # To create a class, you will immediately see this. Let's use a simple example to learn how to create and instantiate classes in C ++ and C.

 
 
  1. # Include
  2. Class MyClass
  3. {
  4. Public: void doSomething ()
  5. {Std: cout<<"This is some text ";
  6. }
  7. };
  8. Void main ()
  9. {MyClass mc;
  10. Mc. doSomething ();
  11. }
  12.  
  13. C # version:
  14. Using System;
  15.  
  16. Class MyClass
  17. {
  18. Public void doSomething ()
  19. {
  20. Console. WriteLine ("This is some text ");
  21. }
  22. }
  23. Class EntryPoint
  24. {Public static void Main ()
  25. {MyClassMc=NewMyClass ();
  26. Mc. doSomething ();
  27. }
  28. }

First, C ++ uses the # include statement to specify the physical path containing the file iostream. h. C # Tells the compiler program to operate in the System namespace. All namespaces and classes belong to the System namespace. C # Use The namespace name to determine the scope of the application (in this example, there is only one namespace in the System), without specifying the File Inclusion Method in the physical path.

Second, the Main program of C # uses Main (note that M is capitalized ). Third, the class declaration of c ++ should end with a semicolon after the ending braces. C # is usable, and is often omitted. Fourth, you can see that the scope of methods and members must be explicitly declared in C. If no declaration is added, the default value is private (only class members can access it), which is the same as that of C ++. C # has five scopes:
Public: other class members can also access
Private: Only class members can access
Protection: Class Members and inherited class members can access
Internal (internal): Only Members in the Assembly can access (C # assembly is a combination of code and resource data, with asmx as the file suffix)

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.