struct table
{
long type;
char* data;
table* next;
};
void main(void)
{
table* bbb;
bbb=new table;
bbb->data=new char[4];
bbb->data="432";
........................
请问到最后如何delete bbb->data,和bbb
}
{
long type;
char* data;
table* next;
};
void main(void)
{
table* bbb;
bbb=new table;
bbb->data=new char[4];
bbb->data="432";
........................
请问到最后如何delete bbb->data,和bbb
}
delete bbb;
bbb->data="432";这样用不对,应该是
bbb->data=new char[4];
strcpy(bbb->data,"432");否则delete时可能会有问题。
bbb->data=new char[4];分配的内存使用delete[] bbb->data, 但是后来你又
bbb->data="432";它指向常量字符串,不能用delete删除.
delete bbb;
delete bbb
{
long type;
CString data;
table* next;
};
用CString不是更好吗?
delete bbb;
{
table(){data=NULL;next=NULL};
~tabke(){if(data!=NULL){delete []data;data=NULL;}if(next!=NULL){delete next;next=NULL;}}
long type;
char* data;
table* next;
};
main()
{
table* bbb;
bbb=new table;
bbb->data=new char[4];
strcpy(bbb->data,"234");
………………………………
delete bbb;
}bbb->data="432";
这种赋值是不对的!
===================================int Compare( LPCTSTR lpsz ) const;Return ValueZero if the strings are identical, < 0 if this CString object is less than lpsz, or > 0 if this CString object is greater than lpsz.ParameterslpszThe other string used for comparison.
if(str1.Compare(str2) > 0)
{
CString t;
t = str1;
str1 = str2;
str2 = t;
}