百分请教,类型转换问题
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.
};