Comparison between objective-C and C ++

Source: Internet
Author: User

Form http://topic.csdn.net/u/20091212/14/eed674bc-b074-4269-8450-f9ca659103c0.html

 

1. The biggest difference: all are object-oriented languages evolved from C.

2. The biggest difference is that C ++ is a static language, while OC is a dynamic recognition language? OC provides a dynamic binding mechanism during runtime.

In oC, the message is sent to an object. It does not matter if the object cannot process the message.

In C ++, Crash.

 

3. Inheritance: OC does not support multiple inheritance.

4. 4. function name resolution is also different. Objective C's function name resolution is based on the function name + parameter name, while C ++ only includes the function name. therefore, the following are valid in Objective C, because the two are parsed to be similar to FOO: bar1 and foo: bar2, respectively;

 

-(INT) Foo :( INT) bar1;

-(Char *) Foo :( INT) bar2;

 

In C ++, the following statements are invalid. compilation errors occur because the two statements are similar to FOO: int, which cannot be identified by the compiler.

 

Int Foo (INT bar1 );

Char * Foo (INT bar2 );

 

5. Objective-C does not have any constructor and destructor in C ++. Its counterpart is alloc-init/free.

 

6. Objective-C 2.0 is added to the garbage collection mechanism (unavailable on iPhone and iPad), while C ++ does not.

 

7. Objective-C does not allow memory allocation on the stack. It can only be performed on heap, while C ++ supports both.

 

8. Objective-C does not support references, but C ++ does.

 

9. Objective-C does not support templates, but C ++ does.

 

10. Objective-C belongs to the Smalltalk system, while C ++ belongs to the simula system.

 

In this case, objective-C is simply packaged on top of C, while C ++ is complicated on top of C ++, however, objective-C makes people feel more elegant and concise.

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.