Sign in to follow this  

The delete[], and the inline

This topic is 4032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Two questions: 1 - if delete is called on a pointer of the base class, which acctually points to an array of objects of the derived class. base_ptr = new DervidObj[100] delete [] base_ptr; What would be the stride for stepping over the next objects in the array upon calling the destructors? the BaseObj size? Then it would be a mess. Correct me if I'm wrong. 2 - If a virtual function is delcared inline, how is it expanded? or is it only treated as a normal function? What about inline's defined in a DLL? Are they expanded too, how? Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by eSam
Two questions:

1 - if delete is called on a pointer of the base class, which acctually points to an array of objects of the derived class.

base_ptr = new DervidObj[100]
delete [] base_ptr;

What would be the stride for stepping over the next objects in the array upon calling the destructors? the BaseObj size? Then it would be a mess. Correct me if I'm wrong.

Undefined behaviour. You cannot treat arrays polymorphically.

Quote:
2 - If a virtual function is delcared inline, how is it expanded? or is it only treated as a normal function? What about inline's defined in a DLL? Are they expanded too, how?

Thanks.

Compiler dependant. Highly unlikely that a dll function will be inlined, although not technically impossible (other languages do run-time optimisation so there's no reason a C++ implementation couldn't). If a virtual function call can be proven to resolve to a particular function at compile time then it's entirely possible the call will be inlined. If not it probably won't. inline is only a hint. There may be an option in your compiler to tell you when a function marked inline wasn't actually inlined if you want to check.

Σnigma

Share this post


Link to post
Share on other sites

This topic is 4032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this