views:

947

answers:

1

Hey guys,

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:

typeof(int)

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

Thanks!

+6  A: 

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

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.

Daniel Earwicker
Note that the keyword int is just an aliasto System.Int32
Martin York
I rolled back the edit that was made, because it was wrong. In C++/CLI (as in C++) things that are contained in a type are accessed with `::` instead of `.` (as used in C#). Earlier C++/CLI compiler versions erroneously allowed the C# syntax. Visual Studio 2010 Beta 1 appears to have blocked it.
Daniel Earwicker
In fact 2008 SP1 doesn't allow it either... why make such an edit to an answer?!
Daniel Earwicker
Sorry. ;-(
Martin York