Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » operator++(bool)

This thread is locked; no one can reply to it. rss feed Print
 1   2 
operator++(bool)
Arthur Kalliokoski
Second in Command
February 2005
avatar

Write out your truth table and all possible outcomes (4 of them).

They all watch too much MSNBC... they get ideas.

GullRaDriel
Member #3,861
September 2003
avatar

torhu said:

Fuck Matthew Leverton, just fuck him.

Bad thread ?

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Bruce Perry
Member #270
April 2000

Arthur, the operator needs to return the old value of the variable from before it was set to true. For example:

bool munge(bool &x) {
    return x++;
}

That function will set x, but it will also return x's old value. To do that, it has to copy it.

Granted the compiler could optimise that away if the x++ appears as a statement with its value unused.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Andrei Ellman
Member #3,434
April 2003

That function will set x, but it will also return x's old value. To do that, it has to copy it.

Now, if x is some large class with an overloaded '++' operator, ++x and x++ can make all the difference, as copying would take longer.

--
Don't let the illegitimates turn you into carbon.

Johan Halmén
Member #1,550
September 2001

{"name":"609921","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/a\/8a20a909009bfcd5bfee645bece22df7.png","w":474,"h":474,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/a\/8a20a909009bfcd5bfee645bece22df7"}609921

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

bamccaig
Member #7,536
July 2006
avatar

 1   2 


Go to: