Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Time for little quiz!
Re: Time for little quiz! [message #2254 is a reply to message #2229] Wed, 05 April 2006 12:31 Go to previous messageGo to previous message
gprentice is currently offline  gprentice
Messages: 260
Registered: November 2005
Location: New Zealand
Experienced Member
unodgs wrote on Wed, 05 April 2006 05:12

luzr wrote on Tue, 04 April 2006 08:02

What is this construct supposed to do (and why):


void CreatePalette(const RGBA *s, int count, RGBA *palette, int ncolors)
{
	delete new sPalMaker(s, count, palette, ncolors);
}



Wink

Mirek


It look very interesting.. but I have no idea what this construction is supposed to do..

I would use delete new if I'd like to create object on heap (but what for?) and to end object live as soon as possible.

The next reason that came to my mind is you don't have to name the object..

But why delete new sPalMaker.. is better than simply
{
sPalMaker pm(s, count, palette, ncolors);
} ?

PS: Maybe this is stupid, but will compiler ignore creating the object if it is not created on heap because the pm isn't used further?





The compiler can ignore creating the pm object if it can determine that doing so makes no difference to the output (observable behaviour) of the program. There are situations where the compiler can elide (means ignore/not do) a call to a copy constructor even if the copy constructor has side effects (modifies a global variable or something) - the famous return value optimisation (RVO) being one - but apart from these, the compiler has to do what you tell it if it makes a difference to the output of the program.

Graeme
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: STL multimap
Next Topic: explanation of c++ typedef line
Goto Forum:
  


Current Time: Wed Apr 30 10:32:54 CEST 2025

Total time taken to generate the page: 0.04679 seconds