I have a Model class:
class Model { ... boost::shared_ptr<Deck> _deck; boost::shared_ptr<CardStack> _stack[22]; };
Deck inherited from CardStack .
I tried to make _stack[0] point to the same as _deck indicates by going:
{ _deck = boost::shared_ptr<Deck>(new Deck()); _stack[0] = _deck; }
_deck of _stack[0] seems to create a copy of _deck . (I know this because changes to _stack[0] do not lead to changes to _deck .) How can I get them to point to the same thing?
Ok - no copy constructor is called. I checked this by doing it and seeing if it was called - it is not.
However - I have a function that works with CardStack objects:
void TransferSingleCard(CardStack & src, CardStack & dst, Face f) { if( !src._cards.empty() ) { src._cards.back().SetFace(f); dst.PushCard(src._cards.back()); src._cards.pop_back(); } }
Now - when I call:
{ TransferSingleCard(*_stack[DECK], _someotherplace, FACEDOWN); std::cout << *_stack[DECK]; std::cout << *_deck; }
I get this output (where std :: cout on CardStack will print the size of this stack):
Num(103) TOP Num(104) TOP
... so I did (wrong?) that _stack[DECK] points to something else.
Deck
class Deck : public CardStack { public: Deck(int numsuits=2, StackIndex index = NO_SUCH_STACK ); Deck::Deck( const Deck & d); int DealsLeft() const; void RecalcDealsLeft(); private: int _dealsleft; };
source share