class Packet
def initialize(name, age, number, array)
@name = name
@age = age
@number = number
@neighbors = array
end
end
p1 = Packet.new("n1", 5, 2, [1,2,3,4])
puts p1.name
Run Code Online (Sandbox Code Playgroud)
我有上面的代码,但每当我执行puts语句时,我得到的错误是name不是方法.
我不知道任何其他方式来打印p1的名称.
如何打印姓名?
所以我有变量:
uint8_t version = 1;
uint8_t ttl = 1;
uint16_t payload_length =
uint32_t account_identifier = 24027;
uint32_t source_address = 0;
uint32_t destination_address = 0;
uint16_t checksum = 0;
uint16_t protocol = 1;
Run Code Online (Sandbox Code Playgroud)
我想按网络字节顺序排列所有值。
我知道用于htons()16 位值和htonl()32 位值。
所以我会这样做:uint32_t source_address = htonl(0);并且uint16_t checksum = htons(0);
8 位值应该使用什么?