That's hard to tell knowing neither the declaration/definition of matSum() nor matrix.
Also, the fact that matrix obviously is a native array (can be concluded from the error message, not the spartanic code snippet) suggests that your program as a whole is native C++. In this case you posted in the wrong forum section. This is the right one: http://www.codeguru.com/forum/forumdisplay.php?f=9
BTW, your code tags are reversed: [/code] is the closing tag, not the opening one.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Well, admittedly the focus of the three main native C++ forum sections isn't completely obvious from just their title, and even the short description doesn't always clear all uncertainties. This is what they're about:
Visual C++: actually Visual C++ together with the MS frameworks MFC/ATL.
Non Visual C++: actually non visual C++ specific. I.e. questions about standard C++ belong there, even if you're using Visual C++ for your program.
C++ and Win API: Windows programming in native C++ without using the frameworks discussed in the Visual C++ section (or rather any framework, mostly raw Win32 API coding there), regardless of what compiler/IDE (including VC++!) you're using.
I was taught a while back that arrays are like follows:
name[3][3];
if I had a variable for exampe size = 3; and I wanted to use it I could do:
name[][size];
That's correct for native C++, but in C++/CLI, as you're describing later on in your post (which BTW now clarifies that you posted in the perfectly correct section), not only the declaration and instantiation of the managed arrays are different, but also the way you pass them to functions as parameters.
now in cli its different, so i set up an array like this:
But how would I input a size into this?
would it be:
name(,size);
You already got declaration and instantiation of the array right, but, as already mentioned, the way you access the indiidual array items or pass such an array as a function parameter is different from native C++ as well, both in declaring/defining the function and calling it.
Here's a small demo of passing a 2D managed array to a function:
Code:
// Test5.cpp: Hauptprojektdatei.
#include "stdafx.h"
using namespace System;
void f(array<int, 2> ^an)
{
for (int i = 0; i < an->GetLength(0); ++i) {
for (int j = 0; j < an->GetLength(1); ++j)
Console::Write("{0} ", an[i, j]);
Console::WriteLine();
}
}
int main(array<System::String ^> ^args)
{
array<int, 2> ^an = gcnew array<int, 2>(3, 3);
for (int i = 0; i < 3; ++i)
for (int j = 0; j < 3; ++j)
an[i, j] = i * j;
f(an);
#ifdef _DEBUG
Console::WriteLine("Hit <Enter> to continue...");
Console::ReadLine();
#endif
return 0;
}
Bookmarks