A popular recipe on the BBC Food site requires 525g of grated carrots for a 26cm-wide cake. NHS guidelines state that three heaped tablespoons of cooked carrots counts as a portion, which is about 60g. This suggests that a whole cake contains more than eight portions of carrots, so a largish slice ought to count as one of your five-a-day. We can argue about whether the carrots lose some volume during the cooking process, but you could easily compensate by just eating another slice!
The problem is that each slice also contains more than 900 calories and 50g of fat. If you tried to get all your vegetables from carrot cake, courgette cake and so on, you would be eating 4,500 calories a day and almost four times the recommended amount of fat.