我一類叫做Packet
那我想我QDataStream
重載operator>>
和operator<<
,並在過載功能我叫stream << somIntMember
但其宣佈爲朋友的抱怨爲私有變量,以連載朋友沒有得到私有成員
error: 'int DG::Packet::_state' is private
error: 'DG::Packet::PacketType DG::Packet::_type' is private
這裏是我的標題。
namespace DG{
class Packet{
public:
struct CommonHeader{
public:
quint32 id;
QTime time;
quint32 size;
PacketType packetType;
public:
CommonHeader();
CommonHeader(quint32 sz, PacketType type);
friend QDataStream& operator<<(QDataStream&, const Packet::CommonHeader& header);
friend QDataStream& operator>>(QDataStream&, Packet::CommonHeader& header);
};
private:
PacketType _type;
int _state;
public:
friend QDataStream& operator<<(QDataStream&, const Packet& packet);
friend QDataStream& operator>>(QDataStream&, Packet& packet);
};
}
這裏那張Ciode
#include "packet.h"
using namespace DG;
QDataStream& operator<<(QDataStream& stream, const Packet& packet){
stream << packet._state << packet._type;
return packet.serialize(stream);
}
操作符>>()的第二個參數是怎麼來的? – 2011-04-18 06:10:42
哦!雅ya謝謝你...我只是複製運營商的貼紙<<並將其更改爲運營商>> – 2011-04-18 06:13:48