Cocos2d-x 一些常見宏的作用

來源:互聯網
上載者:User

常見宏

   1)NS_CC_BEGIN cocos2d命名空間開始


   2) NS_CC_END  cocos2d命名空間結束


   3)USING_NS_CC 聲明cocos2d命名空間


   4)CC_SYNTHESIZE_READONLY(varType, varName, funName)聲明一個成員變數以及getfunName函數,沒有set函數。getfunName已經實現,其實現就是返回這個值。


/** CC_SYNTHESIZE_READONLY is used to declare a protected variable. We can use getter to read the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. @warning : The getter is a public inline function. The variables and methods declared after CC_SYNTHESIZE_READONLY are all public. If you need protected or private, please declare. */#define CC_SYNTHESIZE_READONLY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void) const { return varName; }#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }

 

   5)CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName) 類似CC_SYNTHESIZE_READONLY,不過getfunName返回的是引用。


#define CC_SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }

   6)CC_SYNTHESIZE(varType, varName, funName) 聲明一個成員變數以及getfunName,setfunName函數.函式宣告和實現都有。


/** CC_SYNTHESIZE is used to declare a protected variable. We can use getter to read the variable, and use the setter to change the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. "set + funName" is the name of the setter. @warning : The getter and setter are public  inline functions. The variables and methods declared after CC_SYNTHESIZE are all public. If you need protected or private, please declare. */#define CC_SYNTHESIZE(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void) const { return varName; }\public: virtual void set##funName(varType var){ varName = var; }

   7)CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName) 類似CC_SYNTHESIZE,不過getfunName返回的是引用。

 

#define CC_SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void) const { return varName; }\public: virtual void set##funName(const varType& var){ varName = var; }

   8)CC_PROPERTY_READONLY(varType, varName, funName) 聲明一個成員變數以及getfunName函數,沒有set函數。getfunName函數的實現要自己實現。


/** CC_PROPERTY_READONLY is used to declare a protected variable. We can use getter to read the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. @warning : The getter is a public virtual function, you should rewrite it first. The variables and methods declared after CC_PROPERTY_READONLY are all public. If you need protected or private, please declare. */#define CC_PROPERTY_READONLY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void);

   9)CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName) 類似CC_PROPERTY_READONLY,不過getfunName返回的是引用。getfunName函數的實現要自己實現。


#define CC_PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void);


   10)CC_PROPERTY(varType, varName, funName) 聲明一個成員變數以及getfunName,setfunName函數.函數實現要自己實現。

/** CC_PROPERTY is used to declare a protected variable. We can use getter to read the variable, and use the setter to change the variable. @param varType : the type of variable. @param varName : variable name. @param funName : "get + funName" is the name of the getter. "set + funName" is the name of the setter. @warning : The getter and setter are public virtual functions, you should rewrite them first. The variables and methods declared after CC_PROPERTY are all public. If you need protected or private, please declare. */#define CC_PROPERTY(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName(void);\public: virtual void set##funName(varType var);


  11)CC_PROPERTY_PASS_BY_REF(varType, varName, funName) 類似CC_PROPERTY,,不過getfunName返回的是引用

#define CC_PROPERTY_PASS_BY_REF(varType, varName, funName)\protected: varType varName;\public: virtual const varType& get##funName(void);\public: virtual void set##funName(const varType& var);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.