弟兄们, 俺怎么也想不通! 下列定义为何编译不通过????

chaolajiao 2005-09-26 10:49:35
win2k sp4 + bcb6

struct PP
{
s_int32 Length ; //int32
char ID [ 4 ];
s_int32 seq [4] ; //int32
char user [ 7 ] ;
s_int32 active[ 4 ] ; //int32
char pass [ 4 ] ;

void show_info(char * s)
{
int32 L = Length .get_it() ; //此处无报错
int32 seq = seq .get_it() ; //此处报错 E2294 Structure required on left side of . or .*
int32 a = active .get_it() ; //此处报错E2294 Structure required on left side of . or .*

sprintf(s ,
"\n s_int32 Length = %8.8x "
"\n char ID [ 4 ] = %4.4c "
"\n s_int32 seq = %8.8x "
"\n char user [ 7 ] = %7.7c "
"\n s_int32 active = %8.8x "
"\n char pass [ 4 ] = %4.4c "
"\n -----------------------------------\n"
,
L ,
ID ,
seq ,
user ,
a ,
pass
);
}

};
...全文
130 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
哦. 原来是忘了去掉 那个数组定义了.

感谢老兄!!!
FengSC 2005-09-26
  • 打赏
  • 举报
回复
老兄 s_int32 seq [4] ; 是什么意思?
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
typedef __int32 int32;

struct s_int32
{
char data[ 4 ];
void set_it( int32 x )
{
int32 z = htonl( x );
memcpy( data, & z, 4 ) ;
}
int32 get_it()
{
int32 z;
memcpy( & z, data, 4);
return ntohl( z );
}
};

struct PP
{
s_int32 Length ; //int32
char ID [ 4 ];
s_int32 seq [4] ; //int32
char user [ 7 ] ;
s_int32 active[ 4 ] ; //int32
char pass [ 4 ] ;

void show_info(char * s)
{
int32 L = Length .get_it() ;//无错
int32 S = seq .get_it() ;//此处报错 E2294 Structure required on left side of . or .*
int32 A = active .get_it() ;//此处报错 E2294 Structure required on left side of . or .*

sprintf(s ,
"\n s_int32 Length = %8.8x "
"\n char ID [ 4 ] = %4.4c "
"\n s_int32 seq = %8.8x "
"\n char user [ 7 ] = %7.7c "
"\n s_int32 active = %8.8x "
"\n char pass [ 4 ] = %4.4c "
"\n -----------------------------------\n"
,

L ,
ID ,
S ,
user ,
A ,
pass
);
}

};


还是报同样的错.
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
int32 seq = seq .get_it() ; //此处报错 E2294 Structure required on left side of . or .*
int32 a = active .get_it() ; //此处报错E2294 Structure required on left side of . or .*


我就是把 int32 seq = ...; 变成 int32 S = ...; 照样通不过!
后面那一句int32 a = active.get_it(); 也报告相同错误.
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
因为牵扯到 字节序 的问题. 我是想把一个int32存为 char[4].
只好封装这个char[4] 形成一个结构 s_int32. 其数据是 char [4]. 而且有2个方法.

对外是 int32, 对内是 char[4]. 但是编译不通过.

应该不是低级错误吧?
FengSC 2005-09-26
  • 打赏
  • 举报
回复
不错才怪。
s_int32 seq[4];
int32 seq = seq.get_it();
都不知道怎么解释,这样是低级错误,有什么想不通的?
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
所有代码:

typedef __int32 int32;

struct s_int32
{
char data[ 4 ];
void set_it( int32 x )
{
int32 z = htonl( x );
memcpy( data, & z, 4 ) ;
}
int32 get_it()
{
int32 z;
memcpy( & z, data, 4);
return ntohl( z );
}
};

struct PP
{
s_int32 Length ; //int32
char ID [ 4 ];
s_int32 seq [4] ; //int32
char user [ 7 ] ;
s_int32 active[ 4 ] ; //int32
char pass [ 4 ] ;

void show_info(char * s)
{
int32 L = Length .get_it() ; //此处无报错
int32 seq = seq .get_it() ; //此处报错 E2294 Structure required on left side of . or .*
int32 a = active .get_it() ; //此处报错E2294 Structure required on left side of . or .*

sprintf(s ,
"\n s_int32 Length = %8.8x "
"\n char ID [ 4 ] = %4.4c "
"\n s_int32 seq = %8.8x "
"\n char user [ 7 ] = %7.7c "
"\n s_int32 active = %8.8x "
"\n char pass [ 4 ] = %4.4c "
"\n -----------------------------------\n"
,
L ,
ID ,
seq ,
user ,
a ,
pass
);
}

};
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
也有定义: typdef __int32 int32;
chaolajiao 2005-09-26
  • 打赏
  • 举报
回复
以上代码的前面有定义:
struct s_int32
{
char data[ 4 ];
void set_it( int32 x )
{
int32 z = htonl( x );
memcpy( data, & z, 4 ) ;
}
int32 get_it()
{
int32 z;
memcpy( & z, data, 4);
return ntohl( z );
}
};

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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