new does three things:
1. allocate memory from the heap
2. initialize the object at the resulting memory location
3. return a pointer to this new object.
What it does not do is set the value of your pointer variable - this is done by the assignment operator '='.
delete does the reverse, in reverse order:
1. take a pointer to an existing object
2. destruct the object
3. deallocate the memory it occupied
What it does not is reset the value of your pointer variable.
Technically it wouldn't be so hard to make delete also reset your pointer variable to 0, but since 'cleaning up' is often done at the end of a function or the end of the scope a pointer is defined in, it is usually not neccessary.
Nevertheless it is a good idea to always explicitely set a pointer to 0 after calling delete on it! Even if your delete is the very last line in your code, someone might later add code to that function, past that line.
That said, it might have been better if the C++ standard required the delete operator to also set the pointer to 0. But it doesn't. Of course, it is possible to overwrite delete, if you really want it that way...
now i want to work with XML file in my dialog based application,please help me to create a xml file that contains some details about application and please help me how to read and update this xml file in my application.
i have no idea about XML file.
if possible please provide me any sample or example fot this.
If I put the function definition in a different obj file than the caller, it fails to link reporting I didn't give definition to _DumpWin32StructFields, actually I do,in another obj, it's just too stupid for the linker to find out.
Is there a solution if I don't put caller and the function together?
A template class or template function is resolved during compile time.
Symbols in an OBJ file are resolved during link time.
So to use templates, you have to provide template source access to the calling file.
The problem you're facing is not because the linker is stupid.
It's because it's the compiler that resolves templates and not the linker.
«_Superman_» I love work. It gives me something to do between weekends.
Thanks, I think you are right. I searched some materials, says the compiler won't embed the template definition( blueprint ) into an obj until it is called. So I simply put it in a common header file, but I am still worried if more than one cpp call the template with the same function prototype.
If you want to use a function from different cpp files you have to make the declaration (the function signature) available to both. In the case of a template function, the same goes for its definition! To avoid code duplication, the right place to put this is a header file, not a cpp file.