Hello,
I am failing to create appropriate array in C++ to pass to a C# method.
The method looks like
public Foo(int[,] data) {..}
in C#. When I try to call it with an array initialized in C++ as:
int inputArray[][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
it fails. So what is the proper way to declare an equivalent of int[,]
in C++? 8 4053
<ol***************@googlemail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
I am failing to create appropriate array in C++ to pass to a C# method.
The method looks like
public Foo(int[,] data) {..}
in C#. When I try to call it with an array initialized in C++ as:
int inputArray[][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
it fails. So what is the proper way to declare an equivalent of int[,]
in C++?
Well, the purists will wince when they read this but ...
.... which C++ language are you talking about? :-)
Arrays in C# are instances of the System::Array class.
In MC++ (VS 2003), to create a managed array of integers you'd make the
declaration
Int32 inputArray[,] = new Int32[4,2];
and the compiler will do the right thing.
Alternatively, you should be able to cook up something using
Array::CreateInstance()
I've not used C++/CLI (in VS 2005) much so I'm not all that familiar with
the syntax using it. My guess is that new is replaced by gcnew in the line
above but that is a WAG.
As for ISO C++ - if you really want your C# code to see a managed array - I
don't think it is an option though I could be wrong.
Regards,
Will
In C++/CLI, you'd declare the array as:
array<int, 2^foo;
or (with value initialization):
array<int, 2^foo = {{1,2}, {3,4}};
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"ol***************@googlemail.com" wrote:
Hello,
I am failing to create appropriate array in C++ to pass to a C# method.
The method looks like
public Foo(int[,] data) {..}
in C#. When I try to call it with an array initialized in C++ as:
int inputArray[][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
it fails. So what is the proper way to declare an equivalent of int[,]
in C++?
I've not used C++/CLI (in VS 2005) much so I'm not all that familiar with
the syntax using it. My guess is that new is replaced by gcnew in the line
above but that is a WAG.
array<int, 2>^ arr = gcnew array<int, 2>(3, 4);
Marcus
Thank Will and David,
array<int, 2^foo = {{1,2}, {3,4}}; is what I needed!
Thanks Will and David,
array<int, 2^foo = {{1,2}, {3,4}}; is what I needed!
<ol***************@googlemail.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
Thank Will and David,
array<int, 2^foo = {{1,2}, {3,4}}; is what I needed!
It's a good thing that thanks aren't necessary because Marcus (who deserved
one) didn't get one and I (who didn't deserve one because I offered a VS2003
solution) got one. :-)
Seriously, the thing that you should take away from this exchange is that
unlike the native case where arrays are simply "objects" layed out
sequentially in memory where the "next" storage location may or may not be
what you expect, arrays are types in their own right in .Net in which the
array's "size" is known.
Regards,
Will
By the way, I gave you the short-form value initialization, which is only
valid in a declaration.
Some people may prefer the long form, which is:
array<int, 2^foo = gcnew array<int, 2>(2,2) {{1,2}, {3,4}};
--
David Anton www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"ol***************@googlemail.com" wrote:
Thank Will and David,
array<int, 2^foo = {{1,2}, {3,4}}; is what I needed!
William DePalo [MVP VC++] schrieb:
<ol***************@googlemail.comwrote in message
news:11**********************@n67g2000cwd.googlegr oups.com...
Thank Will and David,
array<int, 2^foo = {{1,2}, {3,4}}; is what I needed!
It's a good thing that thanks aren't necessary because Marcus (who deserved
one) didn't get one and I (who didn't deserve one because I offered a VS2003
solution) got one. :-)
Seriously, the thing that you should take away from this exchange is that
unlike the native case where arrays are simply "objects" layed out
sequentially in memory where the "next" storage location may or may not be
what you expect, arrays are types in their own right in .Net in which the
array's "size" is known.
Regards,
Will
Typing takes some time, I just overlooked Markus's answer :) Thanks to
you too, Markus! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J. Campbell |
last post by:
I'm a novice with c/c++ and have been reading Eckel's book. I'd like
some feedback on using this method. What I need to do is treat a
string as numeric data. I know how to write functions to...
|
by: Kemal Ozan |
last post by:
Hi,
I am studying K&R book. On the multidimensional Arrays chapter they
say
"int (*daytab)
is a pointer to an array of 13 integers. The parenthesis are necessary
since brackets have higher...
|
by: Anupam |
last post by:
Hi,
This was asked on our school newsgroup by a friend of mine.
He gave the following code and said that it did not print out
the elements of the array. He asked for an explanation for this...
|
by: Devrobcom |
last post by:
Hi
I have an array with 30 int and another array with 1000 int.
If any of the 30 intergers can be found in the 1000 int array I shall return
true.
The contents of the arrays will also change over...
|
by: Bilgehan.Balban |
last post by:
Hi,
The following code:
#include <stdio.h>
// const int const_asize = 10;
#define define_asize = 10;
int array = {1,2,3,4,5,6,7,8,9,0};
|
by: Albert Albani |
last post by:
Hello
I have a problem that I cannot seem to solve
I have a c funtion in a DLL that basically looks like
func_c (some_struct* s) {...}
some_struct is defined like so:
struct some_struct {
|
by: Galahad |
last post by:
I am using the code below to create a integer array.
while(dr.Read())
{
string StateID=dr.ToString();
int FacilityID=Convert.ToInt32(dr.ToString());
int FacilityIDs={FacilityID};
}
...
|
by: andrew_nuss |
last post by:
Hi,
I have a template array class on T with specialization for bloat when T
is void*. Thus when T is really an int*, my base ptr is physically a
void** and needs to be converted to an int**.
...
|
by: beagle197 |
last post by:
Folks,
Attempting to q-sort an array of int pairs, e.g. {{0,1}, {0, 0}, ...}
allocated using malloc/calloc, but the arguments I'm passing to qsort
are producing the incorrect results (see...
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
There is error message when executing my program,
Unhandled exception at 0x00411a49 in test_entern.exe: 0xC0000005: Access
violation reading location 0x00000002.
It is...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |