看到宏声明的一段代码,不知其意求解~
大家好,我是一个C++初学者,最近在看一本书《MUD游戏编程》,第190页上有段宏声明,看不懂声明意思,我摘录了其中的代码,求大家帮忙分析一下:
DatabasePointer.h
#ifndef SIMPLEMUDDATABASEPOINTER_H#define SIMPLEMUDDATABASEPOINTER_H#include <iostream>using std::ostream;using std::istream;// ======================================================// This is the DATABASEPOINTER macro, which defines a // database pointer proxy class. Why macros? Because// I've learned that templates + circular dependencies// are a VERY BAD combination when dealing with simple// one pass compilers, like C++.// ======================================================#define DATABASEPOINTER( pt, t ) \class t; \class pt \{ \public: \ pt( int p_id = 0 ) \ : m_id( p_id ) {} \ \ pt& operator=( int p_id ) \ { \ m_id = p_id; \ return *this; \ } \ \ operator int() \ { \ return m_id; \ } \ \ t& operator*(); \ t* operator->(); \ operator t*(); \ \ int m_id; \}; \ \inline ostream& operator<<( ostream& s, const pt& p ) \{ \ s << p.m_id; \ return s; \} \ \inline istream& operator>>( istream& s, pt& p ) \{ \ s >> p.m_id; \ return s; \}namespace SimpleMUD{DATABASEPOINTER( player, Player )DATABASEPOINTER( item, Item )} // end namespace SimpleMUD#endif
只是声明了一下,这几个运算符,。。。也是重载