• Advertisement
Sign in to follow this  

The const key word

This topic is 4227 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what are the differences between both following prototypes (const key word) : void FillDeck(Card* const wDeck); void deal(const Card* const wDeck); Cheers !!

Share this post


Link to post
Share on other sites
Advertisement
In the deal function you can't modify the actual pointer (not the data pointed to), passing value-types by const is rarely done in practice and is not needed for const-correctnes.

The following will be legal.
void FillDeck(Card* const wDeck)
{
// ShuffleDeck takes a non-const reference
ShuffleDeck(wDeck);
// Do something
}

But in deal you would get an error because wDeck is constant and can only be passed by value or const reference.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement