宏定義中的常見使用

/***
*yy_room
*2015-3-6
*
*
*/
#include <iostream>
#include <cstdio>

using namespace std;

/*
* # 表示將一個宏的參數轉換爲字符串字面量
* ## 將兩邊記號鏈接在一塊兒
*
*/
#define MACRO_GET_SET(T,VarName,FuncName) protected: T VarName; \
        public: \
        T get##FuncName() {return VarName;} \
        void set##FuncName(T temp) {VarName = temp;}

/*
* __VA_ARGS__ 表示可變參數
* __LINR__  表示行號
* __FILE__  文件
* __FUNCTION__ 函數
*/
#define macro_print(format,...) printf(format   "LINE= %d  FILE = %s   FUNCTION = %s",##__VA_ARGS__,__LINE__,__FILE__,__FUNCTION__)


class Test
{
  MACRO_GET_SET(int,x,x)
};

int main()
{

    Test* test = new Test();
    test->setx(10);
    cout<<test->getx()<<endl;


    macro_print("%d  ,  %d,   %s  ",1,2,"1234");
    macro_print("dfdsfdfsd");
    return 0;
}
相關文章
相關標籤/搜索