Hi guys,
I am trying to learn this fantastic language. My question is
Does Structure in c++ contain default constructure and destructure.
And when we allocate memory for structure by new operator like
Struct special
{
int x;
int y;
};
special = new special;

Then if special going to destroy at some point of program. Then it is destroyed just like an object of class or this is done in a different way.

Actually i was wondering to see what happened when a structure variable allocated with new operator and destroyed , also i am using a lot of structure variable in my program for which memory is allocated by new operator. Do i need to take care of freeing structure memory or not?

A Structure in C++ is a class. The only difference between the struct keyword and the class keyword, is that by default struct makes all members not explicitly identified as public. A Class makes all members (unless otherwise noted) private. That's it. No other difference. Struct has a default constructor, or you could specify one. It has a destructor too.... If you make a new struct via new, and you never call delete on it, you will have a memory leak.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.