Jump to content

C++ problem?Black Jack

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Coder Zombie

Coder Zombie

    Newbie

  • Members
  • PipPip
  • 28 posts
I am really use to C ,but not C++ so to ease myself into C++ I thought I would make a black jack game but OO is confusing me a little.It says my get_value() method is not a part of card_deck class or as G++ says

Quote

error: request for member ‘get_value’ in ‘deck’, which is of non-class type ‘card_deck ()()’
card.hpp
#ifndef DECK_HPP
#define DECK_HPP

/*
  A class that defines a card_deck type to represent a deck a cards
*/
class card_deck
{
    private:
/*
  An array of ints with a size of 52 which is the standard size of a deck of cards
*/
    int cards[52];
    public:
/*
  Prototypes for the class methods
  See deck.cpp for method implementations
*/
        card_deck();
        const int get_value(int element);
};

#endif

card.cpp
#include <cstdlib>
#include <ctime>
#include "deck.hpp"

/*
  A constructor method to fill cards[] with int card values then uses
  a Fisher Yates card shuffling algorithm and cstdlib's random to evenly
  shuffle cards[]
*/
card_deck::card_deck()
{
    int value = 1;
    int n = 52;
    int k;
    int temp;
    
    for(int i = 0;i < 52;++i)
    {
        cards[i] = value;
        ++value;
        
        if(cards[i] == 13)
        {
            value = 1;
        }
    }
    
    std::srand(std::time(0));
    
    while(n > 1)
    {
        
        k = (std::rand() % n);
        --n;
        temp = cards[n];
        cards[n] = cards[k];
        cards[k] = temp;
    }
}

/*
  A method that will return the requested element of cards[]
  if it is in range and return -1 if the the element is out of range
*/
const int card_deck::get_value(int element)
{
    if(element > -1 && element < 52)
    {
        return cards[element];
    }
    else
    {
        return -1;
    }
}


Edited by Coder Zombie, 09 January 2009 - 09:05 PM.

I'm the master of code rot

#2
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts

/*
  A method that will return the requested element of cards[]
  if it is in range and return -1 if the the element is out of range
*/
/*const*/ int card_deck::get_value(int element)const
{
    if(element > -1 && element < 52)
    {
        return cards[element];
    }
    else
    {
        return -1;
    }

}

I would do it that way. Also change you prototype.