deleting structure

C

crack

Hi ,
i would like to delete a structure of type
typedef struct Mystruct
{
int a;
TCHAR b[256];
TCHAR*c;
}MYSTRUCT

i am a allocating memory as
MYSTRUCT *Mystr = new (MYSTRUCT );

?but how to free this memeory ???/////
 
I

Ian Collins

crack said:
Hi ,
i would like to delete a structure of type
typedef struct Mystruct
{
int a;
TCHAR b[256];
TCHAR*c;
}MYSTRUCT
Avoid C style declarations, use

struct MYSTRUCT {};

Often all caps names are reserved for macros.
i am a allocating memory as
MYSTRUCT *Mystr = new (MYSTRUCT );
You don't have to add the parenthesis here.
?but how to free this memeory ???/////
delete Mystr;
 
I

Ian Collins

crack said:
as i am getting a ecception after it.
but there is pointer ,how wil free.
After what? Please quote the context you are replying to.

What sort of exception? Please post some code that reproduces the problem.
 
J

Jari

Hello,

I assume that you used TCHAR*c;
If yes, you'll need to free it first before delete the whole struct.

Cheers,
Jari
 
H

Howard

Jari said:
I assume that you used TCHAR*c;
If yes, you'll need to free it first before delete the whole struct.

[Please don't top-post. Place comments in-line with or following what
you're replying to. I've rearragned it.]

Note that your suggestion refers to how to avoid a memory leak of the data
pointed to by that pointer (which would best be handled by a destructor, by
the way). The original poster said there's an exception, which would be
caused by something other than forgetting to call delete on that member.
(But as there's no code shown where the class is used, it's impossible to
know what causes the exception at this point.)

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top