Language/C

[C] double array, 이중포인터 함수파라미터

퓨림노 2012. 12. 10. 10:05

[C] double array, 이중포인터 함수파라미터



// include openCV
#include 
#include 
#include 

// inlcude Basic
#include 
#include 
#include 

using namespace std;
using namespace cv;


double ary[3][3];
double ary1[3][3];


//double* GetDAry() {
// return *ary[0];
//}

// method1
double (*GetAry())[3]
{
	return ary;
}

double *Getary2()
{
	return (double*)ary;
}


void SetAry( double (*R)[3] )
{
	for( int i=0; i<3; i++ ){
		for( int j=0; j<3; j++ ){
			ary[i][j] = R[i][j];
		}
	}
	int a = 5;
}

void main()
{
	int count = 0;
	// init
	for( int i=0; i<3; i++ ){
		for( int j=0; j<3; j++ ){
			ary[i][j] = count++;
		}
	}
	// init
	for( int i=0; i<3; i++ ){
		for( int j=0; j<3; j++ ){
			ary1[i][j] = count++;
		}
	}

	SetAry(ary1);

	//double **p = GetDAry();
	double (*p)[3] = GetAry(); // method1


	for( int i=0; i<3; i++ ){
		for( int j=0; j<3; j++ ){
			cout << p[i][j] <<  " ";   
		}
		cout << endl;
	}

	// openCV
	float data[9] = { 1,2,3,0};
	Mat p3(1,3, CV_32FC1, data );
	cout << p3 << endl;
	int a = 5;
	p3.at(0,0) = 2;

	// 되는거 
	double test = p3.at(0,0);

	// 안되는거 
	double test = p3.at(0,0);
	cout << p3 << endl;
	cout << test << endl;
}


g