如何创建托管类型的指针数组? (C ++ / CLI) [英] How do you create an array of pointers to managed types? (C++/CLI)

查看:117
本文介绍了如何创建托管类型的指针数组? (C ++ / CLI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组cli :: array< float,2我想通过编译一个指针数组来访问它的值的b / b
子集。但是,创建一个类型数组

cli:array< cli :: interior_ptr< float>,2> ...


那么,我该怎么办?

I have an array cli::array<float, 2and I would like to access a
subset of it''s values by compiling an array of pointers. But, it''s not
possible to create an array of type
cli:array<cli::interior_ptr<float>, 2>...

So, what do I do?

推荐答案



< ;我********** @ gmail.com写信息

新闻:11 ******************** @ z24g2000prh.googlegrou ps.com ...

<me**********@gmail.comwrote in message
news:11********************@z24g2000prh.googlegrou ps.com...

>我有一个数组cli :: array< float,2我想访问一个

通过编译指针数组的值的子集。但是,创建一个类型数组

cli:array< cli :: interior_ptr< float>,2> ...


那么,我该怎么做?
>I have an array cli::array<float, 2and I would like to access a
subset of it''s values by compiling an array of pointers. But, it''s not
possible to create an array of type
cli:array<cli::interior_ptr<float>, 2>...

So, what do I do?



我认为interior_ptr是一个原生类型,所以你会使用一个普通的C ++数组(不是

(cli :: array< T ^,2其中T是.NET引用类型)。


当然,您可以在数组中存储整数索引而不是

interior_ptr。

I think interior_ptr is a native type so you''d use a normal C++ array (not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.


10月12日下午4:52 ,Ben Voigt [C ++ MVP]" < r ... @nospam.nospamwrote:
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:

< memeticvi ... @ gmail.comwrote in message


新闻:11 ******************** @ z24g2000prh.googlegrou ps.com ...
<memeticvi...@gmail.comwrote in message

news:11********************@z24g2000prh.googlegrou ps.com...

我有一个数组cli :: array< float,2我想通过编译一个指针数组来访问它的值的b / b $ b子集。但是,创建一个类型的数组是不可能的。
cli:array< cli :: interior_ptr< float>,2> ...
I have an array cli::array<float, 2and I would like to access a
subset of it''s values by compiling an array of pointers. But, it''s not
possible to create an array of type
cli:array<cli::interior_ptr<float>, 2>...


那么,我该怎么办?
So, what do I do?



我认为interior_ptr是一个原生类型,因此你会使用普通的C ++数组(而不是
cli :: array)。您可以创建跟踪句柄的.NET数组当然

(cli :: array< T ^,2其中T是.NET引用类型)。


当然,您可以在数组中存储整数索引,而不是

interior_ptr。


I think interior_ptr is a native type so you''d use a normal C++ array (not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.



我试过使用像这样的跟踪句柄数组...


cli :: array< float ^,2 ^句柄;

cli :: array< float,2 ^ data;


data = gcnew cli :: array< float,2> {

{0,0},

{10,10},

{20,20},

{30,30},

{40,40},

{50,50},

{60,40},

{70,30},

{80,20},

{90,10},

{100 ,0}

};


handles = gcnew cli :: array< float ^,2> {

{data [ 0,0],数据[0,1]},

{数据[1,0],数据[1,1]}

};


data [0,0] = float(100);

data [0,1] = float(100);


MessageBox :: Show(处理[0,0] - > ToString());


在这种情况下,消息框显示0而不是100 ...


我也尝试过替换cli :: array< float ^,2 ^ handle; with

cli :: array< System :: Object ^,2 ^ handle;结果相同......

I''ve tried using an array of tracking handles like this...

cli::array<float ^, 2^handles;
cli::array<float, 2^data;

data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};

handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};

data[0, 0] = float(100);
data[0, 1] = float(100);

MessageBox::Show(handles[0, 0]->ToString());

In this case the message box displays 0 instead of 100...

I''ve also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...




< me ********** @ gmail。在消息中写道

新闻:11 ********************** @ z24g2000prh.googlegr oups.com ...

<me**********@gmail.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...

10月12日下午4:52,Ben Voigt [C ++ MVP]" < r ... @nospam.nospamwrote:
On Oct 12, 4:52 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:

>< memeticvi ... @ gmail.comwrote in message

新闻:11 ******************** @ z24g2000prh.googlegro ups.com ...
><memeticvi...@gmail.comwrote in message

news:11********************@z24g2000prh.googlegro ups.com...

>我有一个数组cli :: array< float,2我想通过编译一个指针数组来访问它的值的b / b $ b子集。但是,创建一个类型的数组是不可能的。
cli:array< cli :: interior_ptr< float>,2> ...
>I have an array cli::array<float, 2and I would like to access a
subset of it''s values by compiling an array of pointers. But, it''s not
possible to create an array of type
cli:array<cli::interior_ptr<float>, 2>...


那么,我该怎么办?
So, what do I do?


我认为interior_ptr是一个原生类型,所以你会使用一个普通的C ++数组
(不是
cli :: array)。你可以创建跟踪句柄的.NET数组当然
(cli :: array< T ^,2其中T是.NET引用类型)。

当然,你可以存储整数索引在数组而不是
interior_ptr。


I think interior_ptr is a native type so you''d use a normal C++ array
(not
cli::array). You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type).

Of course, you could store integer indices in the array instead of
interior_ptr.



我试过使用像这样的跟踪句柄数组...


cli :: array< float ^,2 ^句柄;

cli :: array< float,2 ^ data;


data = gcnew cli :: array< float,2> {

{0,0},

{10,10},

{20,20},

{30,30},

{40,40},

{50,50},

{60,40},

{70,30},

{80,20},

{90,10},

{100 ,0}

};


handles = gcnew cli :: array< float ^,2> {

{data [ 0,0],数据[0,1]},

{数据[1,0],数据[1,1]}

};


data [0,0] = float(100);

data [0,1] = float(100);


MessageBox :: Show(处理[0,0] - > ToString());


在这种情况下,消息框显示0而不是100 ...


我也尝试过替换cli :: array< float ^,2 ^ handle; with

cli :: array< System :: Object ^,2 ^ handle;结果相同...


I''ve tried using an array of tracking handles like this...

cli::array<float ^, 2^handles;
cli::array<float, 2^data;

data = gcnew cli::array<float, 2>{
{0, 0},
{10, 10},
{20, 20},
{30, 30},
{40, 40},
{50, 50},
{60, 40},
{70, 30},
{80, 20},
{90, 10},
{100, 0}
};

handles = gcnew cli::array<float ^, 2>{
{data[0, 0], data[0, 1]},
{data[1, 0], data[1, 1]}
};

data[0, 0] = float(100);
data[0, 1] = float(100);

MessageBox::Show(handles[0, 0]->ToString());

In this case the message box displays 0 instead of 100...

I''ve also tried replacing cli::array<float ^, 2^handles; with
cli::array<System::Object ^, 2^handles; with the same result...



我说你可以制作.NET数组跟踪句柄当然

(cli :: array< T ^,2其中T是.NET引用类型。)


关键是T必须是引用类型。 System :: Single不是。由于

a结果,你得到拳击,这意味着一个独立的副本。


实际上,只有interior_ptr可以让你自己更改阵列。

interior_ptr是一个非基本的本机类型,因此你不能将它与

cli :: array一起使用。所以要么:存储索引而不是指针,或使用本地

数组的interior_ptr。

I said "You can make .NET arrays of tracking handles of course
(cli::array<T^, 2where T is a .NET reference type)."

The key there is that T must be a reference type. System::Single isn''t. As
a result, you get boxing, which means an independent copy.

Actually, only interior_ptr will let you change the array itself.
interior_ptr is a non-fundamental native type, so you can''t use it with
cli::array. So either: store indices instead of pointers, or use a native
array of interior_ptr.


这篇关于如何创建托管类型的指针数组? (C ++ / CLI)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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