我想在 Digitalmars D 的同一行初始化一个结构并返回它。我该怎么做?
struct Record {
immutable(ubyte) protocolVersion;
immutable(ubyte) type;
immutable(ushort) requestId;
}
class test {
Record nextRequest() {
ubyte buffer[512];
auto bytesReceived = socketIn.receive(buffer);
if(bytesReceived < 0)
throw new ErrnoException("Error while receiving data");
else if(bytesReceived == 0)
throw new ConnectionClosedException();
return {
protocolVersion:1, //52
type:1, //53
requestId:1 //54
}; //55
} //56
} // 57
这段代码给了我编译错误:
file.d(53): Error: found ':' when expecting ';' following statement
file.d(54): Error: found ':' when expecting ';' following statement
file.d(55): Error: expression expected, not '}'
file.d(56): Error: found '}' when expecting ';' following return statement