Programming/Non programming

Monday, April 19, 2010

Objective C versus C++

Objective C versus C++


Here are the main points of difference between C++ and Objective-C;

  • Objective C is geared towards Run-time decisions and C++ is geared towards Compile-time decisions.
  • C++ comes with large standard libraries which included several container classes and Objective C includes only object-oriented features to C.
  • In C++, variables are called attributes and functions called member function and in Objective-Cits called as instance data and methods.
  • In C++, attributes and methods are inside the braces of the class and In Objective-C, these are not mixed, attributes are declared in braces and methods are declared in outside of the braces. Class implementation will be in @implementation block and class declaration will be in @interface instead of @class.
  • Major difference is with Objective-C and C++ is, It is possible to implement a method without  declaring that in interface in Objective-C. These methods are called Well-Known methods. All methods are virtual, so there is no keyword virtual exits in Objective-C.
  • In C++, two functions can have same name as long as their parameters have different parameters like below.    
int func1(int);   
int func1(float);


In Objective-C, all functions are C, it cannot be overloaded. But if the parameter labels are differe
nt, then it is acceptable to use the same function name for two different. Something like below:

int func1:(int) param1 :(int) param2;
int func1:(int) param1 myLabel:(int) param2;
  • The following modifiers can be added in C++ to the prototype of a function. But that is not possible in Objective-C:
const, 
static (it is done by using "+" and "-"), 
virtual (keyword is useless because all are virtual), 
friend(there is no "friend" notion), throw.

  • Objective-C supports Single Inheritance but not Multiple Inheritance instead it has protocols.
  • In C++, class can be derived from one or several other classes using public, private or protected mode. In this, super class can be accessed using scope resolution operator (::).  In Objective-C, only one class only derived from public mode. Super class can be accessed using (false) keyword "super" like in Java.


Cheers!

M.P.Prabakar
Senior Systems Analyst.

Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

No comments:

Post a Comment