jeudi 1 février 2018

unique_ptr vs shared_ptr - design

I'm writing a card game. I have the following classes: Card, Deck, Player, Board, GameLogic.

Deck holds a vector of unique_ptr Cards. Then a card is drawn from the deck and passed to a player. Then player picks a card and puts... Here I have a design problem. Because up to now it's totally fine to have a unique_ptr. But then I want to pass a card to both Board and GameLogic.

Currently I converted a unique_ptr to shared_ptr. But I find it either ugly and not logical.

I believe that proper usage of pointers is very important and should tell you about the lifetime of a variable. I'm doing something wrong but don't know what...

Do you have some suggestion about how to solve it?

Aucun commentaire:

Enregistrer un commentaire