一个宏定义的错误,小弟看不懂,请高手进来看看,有一定的难度

sh_liyu98 2006-11-27 12:07:11
#define PI_SAME(name, type) \
struct name { \
name() { } \
name(type value) { data = value; } \
name(const name & value) { data = value.data; } \
name & operator =(type value) { data = value; return *this; } \
name & operator =(const name & value) { data = value.data; return *this; } \
operator type() const { return data; } \
friend ostream & operator<<(ostream & s, const name & v) { return s << v.data; } \
friend istream & operator>>(istream & s, name & v) { return s >> v.data; } \
private: type data; \
}


#define PI_LOOP(src, dst) \
BYTE *s = ((BYTE *)&src)+sizeof(src); BYTE *d = (BYTE *)&dst; \
while (s != (BYTE *)&src) *d++ = *--s;

#define PI_DIFF(name, type) \
struct name { \
name() { } \
name(type value) { operator=(value); } \
name(const name & value) { data = value.data; } \
name & operator =(type value) { PI_LOOP(value, data); return *this; } \
name & operator =(const name & value) { data = value.data; return *this; } \
operator type() const { type value; PI_LOOP(data, value); return value; }; \
friend ostream & operator<<(ostream & s, const name & value) { return s << (type)value; } \
friend istream & operator>>(istream & s, name & v) { type val; s >> val; v = val; return s; }
private: type data; \
}
#if PBYTE_ORDER==PLITTLE_ENDIAN
PI_SAME(PInt16l, PInt16);
#elif PBYTE_ORDER==PBIG_ENDIAN
PI_DIFF(PInt16l, PInt16);
#endif

本代码来自于H323的开源代码,PWLIB中的,在编译中发现一个错误
--------------------Configuration: Console - Win32 Release-----------------
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(39) : warning C4100: '_P' : unreferenced formal parameter
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xmemory(41) : warning C4100: '_P' : unreferenced formal parameter
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(296) : warning C4663: C++ language change: to explicitly specialize class template 'codecvt' use the following syntax:
template<> class codecvt<unsigned short,char,int> ...
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(387) : warning C4018: '<' : signed/unsigned mismatch
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(519) : warning C4663: C++ language change: to explicitly specialize class template 'ctype' use the following syntax:
template<> class ctype<char> ...
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(552) : warning C4100: '_D' : unreferenced formal parameter
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xlocale(554) : warning C4100: '_D' : unreferenced formal parameter
..\..\..\include\ptlib/object.h(2526) : error C2143: syntax error : missing ';' before 'private'
..\..\..\include\ptlib/object.h(2526) : error C2146: syntax error : missing ';' before identifier 'data'
..\..\..\include\ptlib/object.h(2526) : error C2501: 'type' : missing storage-class or type specifiers
..\..\..\include\ptlib/object.h(2526) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

哪个兄弟能帮我解释下这段代码是什么意思,中间有错误,我不知道怎么去修改
小弟不胜感激


...全文
360 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
OOPhaisky 2006-12-04
  • 打赏
  • 举报
回复
看着头晕ing。。。
怎么定义了这么大的一个宏阿??
jimmy212 2006-12-04
  • 打赏
  • 举报
回复
没找到错误!
sh_liyu98 2006-12-04
  • 打赏
  • 举报
回复
由于缺少了一个\\的问题
greenteanet 2006-11-28
  • 打赏
  • 举报
回复
看看struct和class中是否少了';'
lann64 2006-11-27
  • 打赏
  • 举报
回复
没什么错误呀。
你编译的时候,前面定义了PInt16吗?
#include <iostream>
using namespace std;
加上了吗?
KUCHIBUE 2006-11-27
  • 打赏
  • 举报
回复
还有,struct和class的定义后面应该有分号
KUCHIBUE 2006-11-27
  • 打赏
  • 举报
回复
同意 lann64(昆仑大鹏@迦楼罗)
sh_liyu98 2006-11-27
  • 打赏
  • 举报
回复
更正下


#define PI_DIFF(name, type)\
class name { \
name() { } \
name(type value) { operator=(value); } \
name(const name & value) { data = value.data; } \
name & operator =(type value) { PI_LOOP(value, data); return *this; } \
name & operator =(const name & value) { data = value.data; return *this; } \
operator type() const { type value; PI_LOOP(data, value); return value; } \
friend ostream & operator<<(ostream & s, const name & value) { return s << (type)value; } \
friend istream & operator>>(istream & s, name & v) { type val; s >> val; v = val; return s; } \

private:\
type data; \
}

程序还是那两个错误
lann64 2006-11-27
  • 打赏
  • 举报
回复
这一行 friend istream & operator>>(istream & s, name & v) { type val; s >> val; v = val; return s; }
后面少了个'\',其他没什么错了。
sh_liyu98 2006-11-27
  • 打赏
  • 举报
回复
都定义了

64,683

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧