用整数引用c#的封送结构
Marshal structure with integer references to C#
嗨,我正在尝试创建和编组以下结构从c#到c++,并维护链接的引用。我不确定这个结构应该如何在c#中定义?在c++中,结构必须如下所示,并保留const引用:
// C++
struct {
int a; // my value
const int& b = a; // my reference to a
}
有人知道这是可能的吗?
谢谢。
编辑:
这更能代表我想要完成的事情,正如@Hans指出的那样,它不是合法的c++,但也许有人可以建议一个更好的路径?system_t
在c++或c#中生成,并传递给c++。我最好的猜测是:(如果这是一个好的设计模式)是初始化c++中system_t
构造函数中的所有引用。至于c#的封送处理,它会变得很复杂。
struct system_t
{
float sysSampleRate = 112500.0f; // Sample rate from receivers.
// Illegal statement @Hans
struct tvg_t // tvg_t is passed to tvg processor
{
float tvgLinearGain;
const float& tvgSampleRate = sysSampleRate; // Get the rate from system.
// Illegal statement @Hans
} tvg; // Nested tvg_t in system_t.
//... Many other structures and variables ..//
};
我想找到正确的设计模式,而不是放弃这个,去一个平面结构或传递system_t
到每个模块。
应该可以:
[StructLayout(LayoutKind.Sequential)]
public struct MyCStruct {
public int a;
public IntPtr b;
}
相关文章:
- Qsort() 比较结构体整数的总和
- 如何修改此函数,以便如果函数的参数是特定结构,则返回具有较大整数的结构?
- boost::任何带有结构体和无符号整数
- 如何在 C++11 编译时构建具有递增值的整数成员的结构序列
- 结构上溢出的整数加法
- 如何将结构名称更改为整数?
- 从低到高组织整数并在C++中使用结构
- 结构中的整数、字符和浮点数
- C 中的内存模型:为什么在同一内存位置分配了结构中的两个整数
- C :对矢量进行排序< struct>(结构有2个整数)基于结构的整数之一
- 在指向结构的指针中访问指向整数的指针
- C MPI创建并发送具有字段char [16]和整数的结构数组
- C++ - 泛型结构的成员在分配双精度时给出错误的值(但适用于整数)
- 在英特尔x86体系结构上使用非AVX指令修改xmm整数寄存器值
- 在处理结构模板中的整数时如何修复"X 不是类模板"?
- 可用于存储和管理整数集合的最佳C++数据结构是什么
- 哪种数据结构和设计用于选择最佳整数集
- 为什么使用 24 位整数时结构大小不会改变
- 我想通过scanf将字符和整数输入到结构中
- 以整数为值的结构