Destroy CString instance?
-
Suppose I have the following function which is executed many times in a program. Is a separate
CString textSub
instance created each time the function executes? Do I need to destroy theCString textSub
at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }
-
Suppose I have the following function which is executed many times in a program. Is a separate
CString textSub
instance created each time the function executes? Do I need to destroy theCString textSub
at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }
Oliver123 wrote:
Is a separate CString textSub instance created each time the function executes?
Of course. You don't need to clean it up, it's not a pointer, it will clean itself up ( calling it's own destructor )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Suppose I have the following function which is executed many times in a program. Is a separate
CString textSub
instance created each time the function executes? Do I need to destroy theCString textSub
at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }
Unless you use a "
new
" operator explicitly,it gets cleaned up automatically once it looses it's scope (Once it returns back to the caller). If you had used "new
" to instantiate the object,then you need to "delete
" it mannualy.
Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"
-
Suppose I have the following function which is executed many times in a program. Is a separate
CString textSub
instance created each time the function executes? Do I need to destroy theCString textSub
at the end of the function? Or suppose it wasn't CString, but some other class? Thanks.void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }