The delete[], and the inline

Started by
1 comment, last by eSam 17 years, 4 months ago
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.
Advertisement
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
I see, thanks!

This topic is closed to new replies.

Advertisement