/*
* File: main.cpp
* Author: Vicky.H
*
*/
#include <iostream>
class Command {
public:
virtual void func1(const char* command) = 0;
virtual void func2(const char* command) = 0;
void setName(const char* name) {this->_name = name;}
const char* getName(void) {return this->_name;}
const char* getDesc(void) {return this->_desc;}
protected:
const char* _desc; /**命令注解*/
private:
const char* _name; /**命令名称*/
};
// 使用宏,拼接方式创建类,并且使用宏参数为类对象属性赋值
#define REGISTER_COMMANDCLASS(classname,desc,Ret) \
class Command_##classname : public Command{ \
public: \
Command_##classname(){ \
this->_desc = #desc; \
setName(#classname); \
} \
void func1(const char* co
使用宏动态创建类
最新推荐文章于 2022-11-08 10:35:58 发布