c++ - 将通用 typdef 结构传递给 C++ 中的函数
问题描述
我正在研究 Arduino,我正在编写通用 cpp 类以在 i2c 中进行通信。我想知道是否可以typedef struct
在函数中传递一个表示寄存器的泛型,像这样
typedef struct {
uint8_t not_used_01 : 1;
uint8_t i3c_disable : 1;
uint8_t den_lh : 2;
//some other attributs
} reg_ctrl9_xl_t;
typedef struct {
uint8_t not_used_01 : 1;
uint8_t odr_h : 1;
uint8_t ord_lh : 1;
//some other attributs
} reg_ctrl5_g_t;
我的头文件
class I2c
{
public:
I2c(uint8_t address);
void writeStruct(uint8_t register_addr, <what data type here??> register_struct);
//some other functions
private:
uint8_t _address;
}
我不知道这是否可能,我不知道我应该输入哪种数据类型,register_struct
因为这里我有 2 个寄存器,例如reg_ctrl9_xl_t
,我reg_ctrl5_g_t
正在寻找一个通用参数函数writeStruct
解决方案
推荐阅读
- matlab - 如何使用 Octave 或 MATLAB 计算贝叶斯估计量
- google-chrome - LiveReload 扩展在 Mozilla 上有效,但在 Chrome 或 Brave 上无效的原因可能是什么?
- mysql - 获取特定人员的列中最常见的值
- javascript - 使用 onChange 函数和 React Hooks 添加多个文件,但单独添加
- vb.net - vb.net 定位光标比文本框长度大一格
- python - CSV 中 Pandas 数据框列中的字典
- python - 消息:元素已禁用,因此可能无法用于在 pythonanywhere.com 上使用 Selenium 的操作错误
- .net-core - 无法在 ef 核心中与 ApplicationUser 创建多对多关系
- php - PHP 构造函数导致“调用未定义的方法”
- java - Android Studio - 如何停止重置到 ScrollView 的顶部