簡體   English   中英

具有整數引用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使用平面結構或將system_t傳遞給每個模塊。

這應該工作:

[StructLayout(LayoutKind.Sequential)]
public struct MyCStruct {
  public int a;
  public IntPtr b;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM