如何翻译“数组” C ++的参数? [英] How to translate "array of" param to C++?

查看:61
本文介绍了如何翻译“数组” C ++的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的游戏引擎(由Delphi XE制作)开发c ++语言绑定。我该如何转换 OleVariant数组 const数组参数以在C ++方面正常工作?

I'm working on c++ language bindings for our game engine (made with Delphi XE). How would I translate the array of OleVariant and array of const params to work properly in C++ side?

function  DLM_CallRoutine(const aFullname: PWideChar;
const aParamList: array of OleVariant): OleVariant; stdcall;

function  DLM_CreateObject(const aClassName: PWideChar;
const aParamList: array of const): Integer; stdcall;

谢谢。

推荐答案

Delphi具有两种完全独立的数组语义,它们都出于不同的目的而使用相同的 代码语法数组。

Delphi has two completely separate array semantics that both use the same array of code syntax for different purposes.

当使用数组声明数据类型或变量时,将使用动态数组,例如:

When array of is used to declare a data type or variable, a Dynamic Array is being used, eg:

type
  TIntegerArray: array of Integer;

var
  Array1: TIntegerArray;
  Array2: array of Integer;

在C ++中,这些对应于 DynamicArray< T> 模板类,例如:

In C++, these correspond to the DynamicArray<T> template class, eg:

typedef DynamicArray<int> TIntegerArray;

TIntegerArray Array1;
DynamicArray<int> Array2;

另一方面,当 数组直接在函数参数中使用(即,不使用typedef),然后使用 Open Array 代替,即:

On the other hand, when array of is used in a function parameter directly (ie, without using a typedef), then an Open Array is being used instead, ie:

procedure DoSomething(Arr: array of Integer);
procedure DoSomethingElse(Arr: array of const);

传递给Open Array参数的值由编译器使用两个单独的参数传递-指向实际数组,以及数组中最后一个元素的索引。 Delphi隐藏了这一事实,因此编码人员只能看到一个参数,并提供了一种简单的语法来指定参数值:

Values passed to an Open Array parameter are passed by the compiler using two separate parameters - a pointer to the actual array, and the index of the last element in the array. Delphi hides this fact so the coder only sees one parameter, and provides a simple syntax for specifying the parameter values:

DoSomething([12345, 67890]);
DoSomethingElse(['Hello', 12345, True]);

但是在C ++中,显式声明了用于数组的两个参数,并且通常指定值使用 OPENARRAY() ARRAYOFCONST()宏,例如:

In C++, however, the two parameters used for the array are explicitally declared, and values are typically specified using the OPENARRAY() and ARRAYOFCONST() macros, eg:

// despite their names, the Size parameters are actually indexes.
// This misnaming has already been slated to be fixed in a future
// C++Builder release...
void __fastcall DoSomething(int const *Arr, const int Arr_Size);
void __fastcall DoSomethingElse(TVarRec const *Arr, const int Arr_Size);

DoSomething(OPENARRAY(int, (( 12345, 67890 )) );
DoSomethingElse(ARRAYOFCONST(( "Hello", 12345, true )) );

这篇关于如何翻译“数组” C ++的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆