====== Objective-CとC++ ====== ===== #include ===== Objective-Cでは1度しかインクルードしない仕組みが、実装されているので#ifdefを書く必要がありません。 ^           c++           ^         Objective-C         ^ |#ifndef HEADER_T\\ #definde HEADER_H\\   :\\ #endif| | |#include "test.h"|#import "test.h"| ===== クラス定義 ===== Objective-Cとc++で一番違うのがクラス定義。\\ @interfaceから@endがクラス定義で、publicなどのアクセス指定子は指定することができない。\\ コンストラクタの代わりにinit、デストラクタの代わりにdeallocを使う。\\ initは自動的に呼ばれないので、意図的に呼ぶ必要がある。\\ すごく不便ですがヘッダファイルにはコードを書くことができず、定義しかできない。 ^           c++           ^         Objective-C         ^ |class point_t {\\   public :\\     point_t() ;\\     ~point_t() ;\\     void set(int x,int y)\\   public :\\     int x ;\\     int y ;\\ } ;|@interface : NSObject {\\   int x ;\\   int y ;\\ }\\ - (void)init() ;\\ - (void)dealloc() ;\\ - (void)set:(int)x (int)y ;\\ @end| ===== 引数のない関数(メソッド)の呼び出し ===== 関数(メソッド)は%%->%%ではなく[]でくくる。 ^           c++           ^         Objective-C         ^ |%%test->func()%%|[test func]| ===== 引数がある関数(メソッド)の呼び出し ===== set(int x,int y,int z)の様な関数があった場合、2番目以降の引数には名前を付けて引数を渡す。 ^           c++           ^         Objective-C         ^ |%%test->set(12,34,56)%%|[test func:12 y:34 z:56]|