gpt4 book ai didi

c++ - sf::Packet 定义的 operator<< 是否与 sf::Packet 派生类的 (*this) 一起工作?

转载 作者:行者123 更新时间:2023-11-30 03:47:13 24 4
gpt4 key购买 nike

我得到了一个派生自 sf::Packet 的类,它在其构造函数中传递了一个引用 iots 类型的 Integer。现在在构造函数中,我尝试将 Integer 添加到 sf::Packet 的数据中,如下所示:

class Packet : public sf::Packet
{
public:
Packet(sf::Int32 type)
{
m_Type = type;
(*this) << m_Type;
}

sf::Int32 m_Type
}

但是,如果我尝试在服务器端使用运算符提取该整数>>,该整数将保持其初始化状态。

现在我的问题是:在这种情况下,甚至可以将此运算符与 this 指针一起使用吗?

最佳答案

Now my Question: Is it even possible to use this operator with the this pointer in this case?

是的,没关系。看看下面的例子:http://coliru.stacked-crooked.com/a/b8f8d5b45ade0ad8 .

您应该能够自行使用调试器验证这一点。

However if I try to extract that Integer on the server side with the operator>>

有可能错误发生在其他地方

关于c++ - sf::Packet 定义的 operator<< 是否与 sf::Packet 派生类的 (*this) 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33761907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com