我的C++库

  1. c++基类hpp文件
    • 包含GET_SET宏定义,用来生成get和set函数
    • 对编译器版本有要求,目前可以在gcc/g++ 4.9.1上编译通过
#ifndef _MAJIAOOBJECT_H 
#define _MAJIAOOBJECT_H 

#include <string>
#include <iostream>
using namespace std; 

#define MAJIAO_FIELD_DEFINE(type, field) type field

#define GET_SET(access_permission, type, name)
    access_permission:
        MAJIAO_FIELD_DEFINE(type, name);
    public:
        inline void set##name(type v){
            this->name = v;
        }
        inline type get##name(){
            return this->name;
        }


class MajiaoObject { 
    public :  
        GET_SET(public, int, id)

        MajiaoObject() {  } 
        ~MajiaoObject() {  } 

        virtual string toString() { return ""; }
} ; 
#endif	// _MAJIAOOBJECT_H

原文地址:https://www.cnblogs.com/majiao61/p/14902584.html