two dimensional pointer array casting (C question)
-
Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1:
double m_aCoefficients[10][20];
and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2:double* m_pCoefficients[10][20];
and in my CMyDoc Class I have tried this:m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients;
but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanks -
Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1:
double m_aCoefficients[10][20];
and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2:double* m_pCoefficients[10][20];
and in my CMyDoc Class I have tried this:m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients;
but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanksPointer declaration have highest priority for the compiler. As multiplication is before additiont. Example: 2*3+4=10. This is about language definition and how the compiler works. Dont know more. :(( you better double* pCoefficients; m_Class2.m_pCoefficients = (double*) &m_Class1.m_aCoefficients[0][0]; or "maybe": double[10][20]* :confused::confused::confused:
Greetings from Germany
-
Hello :) , I have defined a two dimensional array of type double in one of my MFC classes in class 1:
double m_aCoefficients[10][20];
and now I want to make a pointer to this variable in another of my classes and assign address of this double array to that pointer. so i have defined in class 2:double* m_pCoefficients[10][20];
and in my CMyDoc Class I have tried this:m_Class2.m_pCoefficients = (double*[10][20]) &m_Class1.m_aCoefficients;
but it gives error Error 4 error C2440: 'type cast' : cannot convert from 'double (*)[10][20]' to 'double *[10][20]' How can I resolve this? thanks -
Electronic75 wrote:
double* m_pCoefficients[10][20];
Here you should have
double (*m_pCoefficients)[20];
After this you can write
m_Class2.m_pCoefficients = m_Class1.m_aCoefficients;
I hope it helps..
Regards, Sandip.
Thanks Sandip It works fine:rose: