如何在托管C ++中使用typeof(int)?

时间:2022-09-01 14:23:20

I am working on a project now and part of it uses Managed C++. In the managed C++ code, I am creating a DataTable. While defining the Columns for the datatable, I need to specify the Type of the column. In C#, that would:

我现在正在开发一个项目,其中一部分使用托管C ++。在托管C ++代码中,我正在创建一个DataTable。在为数据表定义列时,我需要指定列的类型。在C#中,那会:

typeof(int)

but how do I do that in Managed C++?

但是我如何在托管C ++中做到这一点?

Thanks!

1 个解决方案

#1


In C++/CLI, use the typeid keyword.

在C ++ / CLI中,使用typeid关键字。

e.g.

Type ^t = Int32::typeid;

In the older "Managed C++ Extensions" syntax, you'd use __typeof(Int32), but that whole version of the language is severely deprecated and you should be using C++/CLI.

在旧的“托管C ++扩展”语法中,您使用__typeof(Int32),但该语言的整个版本已被严格弃用,您应该使用C ++ / CLI。

#1


In C++/CLI, use the typeid keyword.

在C ++ / CLI中,使用typeid关键字。

e.g.

Type ^t = Int32::typeid;

In the older "Managed C++ Extensions" syntax, you'd use __typeof(Int32), but that whole version of the language is severely deprecated and you should be using C++/CLI.

在旧的“托管C ++扩展”语法中,您使用__typeof(Int32),但该语言的整个版本已被严格弃用,您应该使用C ++ / CLI。