What they said.

If you do have to carpet first, remove any quarter round before they carpet. This will push the carpet right up to the baseboards. Then you can paint the quarter round before reinstalling it. That will make it much easier to paint the baseboard without worrying about the carpet as you can leave the bottom bit unpainted and then install the painted quarter round over the unpainted bit.

But don't do what we did...two years later we still haven't put the quarter round back.