Thread: Class Question - Object Orientation

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    22

    Class Question - Object Orientation

    I'm just getting to grips with Object Orientation and am testing out my skills with a game of blackjack. and am a little stuck..

    I've created a class for the DECK of cards which takes note of what cards have been dealt and how many are left in the deck. I have declared and initialiised this class in my main.
    I have now created another class called CARD. This class holds info about type of card and rank of card. in the constructor of the CLASS card i would like to access a function in the already initialized DECK object. Is this possible?
    my code for the CARD constructor below..

    Code:
    card::card()
    {
        int n = pack.deal(); //pack is the object declared in main of class type DECK. 
                                   //deal is a function which of class DECK and returns int.
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Freem View Post
    I've created a class for the DECK of cards which takes note of what cards have been dealt and how many are left in the deck.
    If you hadn't already made a card class by this time, you've already messed it up. It would seem extremely natural for a deck to contain a bunch of cards, so you need to know what a card is first.

  3. #3
    Registered User
    Join Date
    Jul 2011
    Posts
    22
    Yes, of course. This makes sense to me now.

    Thankyou! Its funny how sometimes you just need another perspective

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 05-22-2009, 11:12 PM
  2. Setting an object to predefined angle / orientation
    By sapdev in forum Game Programming
    Replies: 16
    Last Post: 05-19-2009, 07:40 AM
  3. array class object question
    By ExDHaos in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2009, 11:23 AM
  4. Replies: 8
    Last Post: 01-13-2008, 05:57 PM
  5. Replies: 3
    Last Post: 02-12-2002, 10:09 PM

Tags for this Thread