char * is fail in CArray while char[] is success
- From: "MFCQuery" <mfcquery@xxxxxxxxxxx>
- Date: Mon, 7 Aug 2006 16:05:42 +0530
Hi Experts,
i have following structure
typedef struct xy{
int num;
char *val;
}XY;
struct XYArray:public CArray<XY,XY>
{
};
in cpp file, in a function
struct XYArray Obj;
Now i can add XY type variable to Obj like
XY A;
A.num=1; A.val=str;
// suppose str is a char *array which contains some value.
Obj.Add(A); // add XY type variable to Obj
Suppose i add 10 elements to Obj. Now when i get each element of Obj then i
found that value of val field of XY structure has been change. i.e.
XY B=Obj.GetAt(0);
B.val is not which i add in Obj.
While if i declare XY as
typedef struct xy{
int num;
char val[250];
}XY;
and add data to Obj like
XY A;
A.num=1;
memcpy(A.val,str,strlen(str)); // suppose stris a char *array which contains
some value.
Obj.Add(A);
In this case when i get each element of Obj, i found right value.
So please tell how to solve this problem. why char * is fail in CArray?
while char[] is success.
.
- Follow-Ups:
- Re: char * is fail in CArray while char[] is success
- From: Joseph M . Newcomer
- Re: char * is fail in CArray while char[] is success
- Prev by Date: Re: statically link a DLL
- Next by Date: Re: What MFC Objects Can't be created on the Stack?
- Previous by thread: CComboBox problem
- Next by thread: Re: char * is fail in CArray while char[] is success
- Index(es):
Relevant Pages
|