C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-29-2009, 05:48 AM   #1
Registered User
 
Join Date: May 2009
Posts: 6
Returning a multidimensional array from pointer function in Visual C++

Hello,

I wrote following code to return multidimensional array from pointer function.Input parameter of this function is one dimensional array, output is pointer that point multidimensional array.


Code:
double  **function( array< double>^ data,int width,int height ) 

  {int i;
  //define returning variable that point multidimensional array
  double **R;
 // memory allocation for R
 R=new double *[height];
 for (i=0;i<height;i++)
 {
 R[i]=new double [width];
 }

  // ....


  return R;
 }


  int main( void ) {
  int M=2;
  int N=10;
  int  i,j;
  // define multimensional array 2x10

  array< array< double >^ >^ input = gcnew array< array< double >^ >(M);

for (j=0;j<input->Length;j++){
input[j]=gcnew array<double>(N);}

// define result1 and result 2 pointers and memory allocate  for these  variables

 double **result1;
 result1 = new double *[N];
 for(i=0;i<N;i++)
 {result1[i]=new double [M];}

 double **result2;
 result2 = new double *[N];
 for(i=0;i<N;i++)
 {result2[i]=new double [M];}

 //............


// send first row array of multidimensional array to function

 result1=function(input[0],M,N)

// send second row array of multidimensional array to function

 result2=function(input[1],M,N)

// delete  result1 and result2
for (i=0;i<N;i++)
{delete R[k];}
delete R;}

 return 0;
 }
I built this program succesfully in Visual Studio 2008.When I debug this code,the program computed result1 but during computing result2 in the function here:

Code:
R=new double *[height];
for (i=0;i<height;i++)
 {
 R[i]=new double [width];
 }
Visual Studio give this error:

An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in stdeneme.exe Additional information: External component has thrown an exception.

Unfortunately I can't understand this error. How can I overcome of this problem?Could you help me please?

Best Regards..
yalcin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which Library Files for these unreferenced functions? lehe C++ Programming 3 01-31-2009 10:30 PM
C++ std routines siavoshkc C++ Programming 33 07-28-2006 12:13 AM
Calling a Thread with a Function Pointer. ScrollMaster Windows Programming 6 06-10-2006 08:56 AM
<Gulp> kryptkat Windows Programming 7 01-14-2006 01:03 PM
Please Help - Problem with Compilers toonlover C++ Programming 5 07-23-2005 10:03 AM


All times are GMT -6. The time now is 06:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22