共用方式為


可攜性,在 ABI 界限 (現代的 C++)

在二進位的介面範圍中,使用足夠的可攜性類型和慣例。"可攜性類型 」 是 c 的內建型別或結構,其中包含只有 c 的內建型別。類別型別只能使用,當呼叫端和被呼叫端同意版面配置],呼叫慣例、 及其它.兩者都使用相同的編譯器和編譯器設定編譯時,請這樣做才可行。

若要簡維 c 可攜性之類別的方式

當呼叫端可能會被編譯時使用另一種的編譯器語言時,然後 「 簡維化 」 具有特定的呼叫慣例 」 extern C"api:

// class widget {
//   widget();
//   ~widget();
//   double method( int, gadget& );
// };
extern “C” {    // functions using explicit “this”
  struct widget;   // + opaque type (fwd decl only)
  widget* STDCALL widget_create();    // ctor → create new  “this”
  void STDCALL widget_destroy( widget* );    // dtor → consume “this”
  double STDCALL widget_method( widget*, int, gadget* );    // method → use “this”
}

請參閱

其他資源

歡迎回到 C++ (現代的 C++)

C + + 語言參考

標準 C++ 程式庫參考