64,637
社区成员
发帖
与我相关
我的任务
分享
#ifndef OOP_H
#define OOP_H
#define PROPERTY_DECL(className,propertyName) \
public: className get##propertyName() { return m_##propertyName; } \
public: void set##propertyName(className val) { m_##propertyName = val; } \
private: className m_##propertyName;
#define APP_INIT(MainClass) \
int main(int argc,char **argv) \
{ \
MainClass instance; \
}
#endif // OOP_H
#ifndef TEST_H
#define TEST_H
#include "oop.h"
class Test
{
PROPERTY_DECL(int,Count) //注意这里,使用到了这个宏!
public:
Test();
};
#endif // TEST_H
#include "test.h"
#include <iostream>
Test::Test()
{
setCount(10);
std::cout << "Hello!" << std::endl;
std::cout << "Function getCount() result: " << getCount() << std::endl;
}
APP_INIT(Test)