inteq
asked on
How to use pointer array data in MFC?
Dear Experts,
I am passing the pointer array to my function by using MFC exe in visual c++. The followings are my details.
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// ////////// //
In MyAppDlg.h
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CMy7_10_V2Dlg)
...
...
afx_msg void check(CString* a);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
In MyAppDlg.cpp
void CMy7_10_V2Dlg::OnButton1()
{
typedef unsigned char Byte;
// TODO: Add your control notification handler code here
MyString="aaa";
check(&MyString);
}
In MyAppDlg.cpp
void CMy7_10_V2Dlg::check(CStri ng* a)
{
char *temp = new char[16];
m_result = new char[16];
for (int i=0;i<16;i++)
{
temp[i]= a[i];
}
}
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// /
My error is "error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
Error executing cl.exe."
////////////////////////// ////////// ////////// ////////// ////////// //////
Please kindly answer for me how to use the data which is inside the pointer array passed from another function.
Thanks in advance.
Regards.
I am passing the pointer array to my function by using MFC exe in visual c++. The followings are my details.
//////////////////////////
In MyAppDlg.h
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CMy7_10_V2Dlg)
...
...
afx_msg void check(CString* a);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
In MyAppDlg.cpp
void CMy7_10_V2Dlg::OnButton1()
{
typedef unsigned char Byte;
// TODO: Add your control notification handler code here
MyString="aaa";
check(&MyString);
}
In MyAppDlg.cpp
void CMy7_10_V2Dlg::check(CStri
{
char *temp = new char[16];
m_result = new char[16];
for (int i=0;i<16;i++)
{
temp[i]= a[i];
}
}
//////////////////////////
My error is "error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
Error executing cl.exe."
//////////////////////////
Please kindly answer for me how to use the data which is inside the pointer array passed from another function.
Thanks in advance.
Regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also:
temp[i]= (*a)[i];
Note that you have a problem with the string length. You chack 16 character but the string length is 3.
temp[i]= (*a)[i];
Note that you have a problem with the string length. You chack 16 character but the string length is 3.
void CMy7_10_V2Dlg::check(const CString& a)
{
char *temp = new char[16];
m_result = new char[16];
int nMax = min( 16, a.GetLength() );
for (int i=0;i<nMax;i++)
{
temp[i]= a[i];
}
}
Open in new window