누군가 여기서 제게 설명해 주시겠습니까? (나는 C++에 익숙하지 않다.)복사 생성자가 std :: string을 변경합니다.
이진 문자열 스트림을 사용하고 write()
메서드를 호출하여 4 int32_t
으로 시작하는 std::string
이 있습니다.
index
, type
및 tag
(4 int32-ts 중 3 개)이 정확합니다. 이 I 값 함수에 currentSocketInfo
전달할 때
SocketInfo currentSocketInfo;
currentSocketInfo.header.reserve(_headerLength);
int iResult = recv(socket, ¤tSocketInfo.header[0], _headerLength, 0);
auto headerIntPtr = reinterpret_cast<const int32_t*>(currentSocketInfo.header.c_str());
int32_t index = headerIntPtr[1];
int32_t type = headerIntPtr[2];
int32_t tag = headerIntPtr[3];
appendCurrentMessageFromSocket(socket, currentSocketInfo);
하지만, 다음과 동일한 reinterpret_cat 할당을 수행 값은 다르다. (처음에는 0, 1, 0과 같지만 함수 호출 후에는 -252142 <과 같음 - 정확하지 않은 숫자 임). 여기
void SocketListener::appendCurrentMessageFromSocket(SOCKET socket, SocketInfo socketInfo) {
auto headerIntPtr = reinterpret_cast<const int32_t*>(socketInfo->header.c_str());
int32_t index = headerIntPtr[1];
int32_t type = headerIntPtr[2];
int32_t tag = headerIntPtr[3];
}
가
SocketInfo
클래스의 질문에 관련된 부분은 헤더 필드 :
class SocketInfo {
public:
bool waitingForWholeMessage;
std::string header;
std::string body;
int32_t expectedLength;
};
'SocketInfo'란 무엇입니까? 우리에게 [최소한의 완전한 예] (http://stackoverflow.com/help/mcve)를 주시겠습니까? – Beta
SocketInfo 클래스를 추가했습니다. 죄송합니다. –
"값으로 함수에 currentSocketInfo를 전달한 다음 똑같은 reinterpret_cat 및 할당을 수행합니다."해당 코드를 표시합니다. 또한, 어떤 컴파일러를 사용하고 어떤 버전입니까? –