百分请教,类型转换问题

flyingbug flyingbug 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
C++的这种风格的代码是什么意思?是指针的强制类型转换吗?
有什么好处?会不会有什么风险?

Subscription *subscription = (Subscription *) event->data_;

其中
event的data_成员是一个char data_[MAX_PAYLOAD_SIZE];
Subscription 是一个类,定义如下:(也没见到用户定义的类型转换)
class Subscription
{
// = TITLE
// Allows Consumers to subscribe to be routed information
// arriving from a particular Supplier connection id.
public:
void decode (void)
{
this->connection_id_ = ntohl (this->connection_id_);

for (ACE_INT32 i = 0; i < this->total_consumers_; i++)
this->consumers_[i] = ntohl (this->consumers_[i]);

this->total_consumers_ = ntohl (this->total_consumers_);
}
// Decode from network byte order to host byte order.

void encode (void)
{
this->connection_id_ = htonl (this->connection_id_);

for (ACE_INT32 i = 0; i < this->total_consumers_; i++)
this->consumers_[i] = htonl (this->consumers_[i]);

this->total_consumers_ = htonl (this->total_consumers_);
}
// Encode from host byte order to network byte order.

ACE_INT32 connection_id_;
// Connection id.

ACE_INT32 consumers_[MAX_CONSUMERS];
// Connection ids for consumers that will be routed information
// containing this <connection_id_>

ACE_INT32 total_consumers_;
// Total number of these consumers.
};
...全文

相关推荐

评论 28
收藏 已收藏
分享
返回顶部
flyingbug
C++ 语言 65,214 成员 250,514 内容