freelanceprogrammers.org Forum Index » C

Please answer


View user's profile Post To page top
to_ashishm@... Posted: Fri Jan 07, 2005 1:25 am


Joined: 07 Jan 2005

Posts: 3
Please answer
Hi,

Please provide me with the answer to these questions.
 
1. What will happen if I allocate memory using "new" and free it using "free" or allocate sing "calloc" and free it using "delete"?

2. Why can not we have virtual constructor.

Regards/Thanks
Ashish
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Fri Jan 07, 2005 9:36 pm


Joined: 25 Jul 2003

Posts: 48
Please answer
Reply embedded...

> From: ashish maheshwari [mailto:to_ashishm@...]
> Sent: Thursday, January 06, 2005 1:25 PM
> To: Programmers-Town@yahoogroups.com
> Subject: (PT) Please answer
>
> Hi,
>
> Please provide me with the answer to these questions.

> 1. What will happen if I allocate memory using "new" and free it
> using "free" or allocate sing "calloc" and free it using "delete"?

You get undefined behavior.

To all others:
Please do not waste bandwidth and effort by posting reply like:
"I tried it on my compiler and it works".

You`re doing more harm to newbie.

Undefined behaviors include the illusion of producing "working" results.

You cannot learn C/C++ language specifications and concepts by
experimentation. Not every compliable C/C++ codes are well-defined and
well-behaved.


> 2. Why can not we have virtual constructor.

"Virtual" means the type is not known at compiled time but at runtime. For
all other virtual function, the type is indeed known. "Virtual constructor"
means the type is not known when the object is constructed. The catch is,
since the object is not yet constructed, the type is not yet known.

HTH
Shyan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help