将c++中的结构体转换为Ruby
Converting struct in C++ to Ruby
我正在尝试转换此代码:
#pragma once
#include "thread.h"
#include <vector>
struct Process {
enum Type {
SYSTEM,
USER
};
// process ID
int pid;
// process type
Type type;
// threads belonging to this process
std::vector<Thread*> threads;
// constructor
Process(int pid, Type type) : pid(pid), type(type) {}
};
转换成Ruby,但我不明白。我尝试过使用模块,但发现你不能在模块中真正拥有构造函数。我也不太懂ruby结构类。如果有人能解释一下或者帮我转换一下,我将不胜感激。
我认为这可能值得一看:
c++ -结构与类
你的结构是大多数语言(包括Ruby)会调用的类(不是C风格的结构):
class Process
def initialize(pid, type)
@type = type
@pid = pid
@threads = []
end
attr_accessor :type, :pid, :threads
end
您需要attr_accessor
使成员公开(这是c++中结构体的默认行为)
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 递归列出所有目录中的C++与Python与Ruby的性能
- 使用Swig将std::set转换为ruby
- 如何将从 Ruby 数组中取出的字符串转换为 C/C++ 字符串
- Ruby rb_define_method -无效转换
- 转换日期.valueof原语转换为Ruby
- 将c++中的结构体转换为Ruby