|
Dean Seo wrote: if there are some other reasons for this?
a pointer to a block of allocated memory is not set to NULL when you delete that block of memory. you need to pay attention to that fact when deleting memory.
also, in C++ a pointer is not a reference.
int foo(int &a, int *b)
{
...
}
a is a reference. b is a pointer.
|
|
|
|
|
|
Besides the above comments you might want to read up on what a 'heap' represents in computer science both conceptually and via implementations.
|
|
|
|
|
|
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... 
|
|
|
|
|
Technically you are describing the "new expression" and "delete expression".
Not be confused for example with the new operator and delete operator.
|
|
|
|
|
Hi all,
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.
i am waiting for ur valuable suggestions.
please help me for this.
thanks in advance.
|
|
|
|
|
|
there is any working example for this coz use of tinyxml.h generates so many errors.
|
|
|
|
|
There is a working sample on the page that Rajesh pointed you at. If you are getting errors then show the code and the error messages and people will try to help you resolve them.
The best things in life are not things.
|
|
|
|
|
Le@rner wrote: please help me how to read...xml file in my application.
Here is another example.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
thanks its a very gud article.
|
|
|
|
|
|
My c++ test version is 6.74, seems it doesn't support VS2008.Is it possible to set something like "compiler" to make it support VS2008?
|
|
|
|
|
You should rather check Parasoft's[^] site and maybe ask there. If you click the "Supported Environments" tab-thingie on the site it seems to list VS2008.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
template< size_t N >
void cdecl _DumpWin32StructFields( WCHAR (&szBuffer)[N], LPCWSTR pszFormat, ... )
{
va_list pFirstParam ;
va_start( pFirstParam, pszFormat ) ;
StringCchVPrintf( szBuffer, N,pszFormat, pFirstParam ) ;
va_end( pFirstParam ) ;
}
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.
|
|
|
|
|
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.
template< size_t N >
void cdecl _DumpWin32StructFields( WCHAR (&szBuffer)[N], LPCWSTR pszFormat, ... )
{
va_list pFirstParam ;
va_start( pFirstParam, pszFormat ) ;
StringCchVPrintf( szBuffer, N,pszFormat, pFirstParam ) ;
va_end( pFirstParam ) ;
}
#include "dump.hpp"
void foo() {
WCHAR buffer[20];
_DumpWin32StructFields(buffer, _T("Hello World!"));
}
#include "dump.hpp"
void bar() {
WCHAR buffer[30];
_DunpWin32StructFields(buffer, _T("Goodbye Cruel World!"));
}
This will force the compiler to instantiate and create code for your template function for both foo.obj and bar.obj, and the linker won't have trouble finding them.
|
|
|
|
|
Because of some reasons I have to use both VS2005 and VS2008 on my computer.
if it can, is there any thing I should be careful with?
|
|
|
|
|
yes, they can both be installed.
i have VC6, VS03, VS05, VS08 and VS10 on mine. they all work fine together.
|
|
|
|
|
WOW !!!
Didn't you get your hands on any earlier versions???
|
|
|
|
|
i don't need any of the other VCs. but if i could get DOS C 6.0 to run on Win7, i'd have it, too.
|
|
|
|
|
I use Microsoft C 6.0 with DosBox[^] under Windows XP. It should probably work under Windows 7 too.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
It would be a good idea to install the products in the order that they were released. In your case, first install VS 2005 followed by VS 2008.
"Real men drive manual transmission" - Rajesh.
|
|
|
|