Sign in to follow this  

Typecasting error, Blackjack_Game * to Card_Game *

This topic is 3592 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

Type casting error, Card_Game * to Blackjack_Game * Errors, trying to derive a Blackjack_Game class from Card_Game, getting errors when passing the Blackjack_Game pointer to a function that takes a Card_Game pointer.
error C2243: 'type cast' : conversion from 'Blackjack_Game *' to 'Card_Game *' exists, but is inaccessible
error C2243: 'type cast' : conversion from 'Blackjack_Game *' to 'Card_Game *' exists, but is inaccessible
error C2243: 'type cast' : conversion from 'Blackjack_Game *' to 'Card_Game *' exists, but is inaccessible
error C2243: 'type cast' : conversion from 'Blackjack_Game *' to 'Card_Game *' exists, but is inaccessible
Card_Game.h:
class Card_Game
{
public:
	Card_Game(){}
	~Card_Game(){}
	virtual void init(){}
	virtual void cleanup(){}
	virtual void turn_logic(std::string player_id);

	std::vector<std::string> m_vPlayer_List;

	int calculate_winnings();
	void new_setting(std::string name, Setting * new_setting);
	void initialize_players();
	// Give player id a new hand
	void give_player_hand(std::string player_id);
	void shuffle_deck(int deck_id);
	// Draw how_many cards to player id's hand_id from deck_idntyd
	void draw_card(std::string player_id, int hand_id, int deck_id, int how_many);
	void place_bet(std::string player_id, int bet);
	// Split player's active hand
	void split_hand(std::string player_id, int hand_id);
	// check if hand value > check_value
	bool check_hand_value(std::string player_id, int hand_id, int check_value);	

protected:

	Resource_Manager< Player > m_rPlayers;
	Resource_Manager< std::vector<Hand*> > m_rHands;
	Resource_Manager< int* > m_rBets;
	Resource_Manager< Deck* > m_rDecks;
	Resource_Manager< Setting* > m_rSettings;
	std::vector< Deck* > m_vDeck;	

};
And Blackjack_Game.h
class Blackjack_Game : private Card_Game
{
public:
	Blackjack_Game(){}
	virtual void init()
	{
		new_setting( "Minimum Bet", new Integer_Setting(25) );
	}
	virtual void cleanup(){}
	virtual void turn_logic(std::string player_id)
	{
		int m_result;
		switch(m_result)
		{
		case 1: 
			draw_card(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand, 0, 1);
			if(check_hand_value(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand, 21))
			{
				m_rPlayers.get_resource(player_id).px->m_winner = false;
			}
			break;
		case 2: // stay hand
			// while dealer has hand value less than 18
			while(check_hand_value("Dealer", 0, 18))
			{
				draw_card("Dealer", 0, 0, 1); // (for dealer draw to 0 hand, from 0 deck, 1 card)
			}
			// if the dealer goes over 21
			if (check_hand_value("Dealer", 0, 21))
			{
				// player wins
				m_rPlayers.get_resource(player_id).px->m_winner = true;
				//state_manager->change_state( Deal_State::instance(), game );
			}
			// if player's hand value is greater than the dealer's
			else if( check_hand_value(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand, 
				m_rHands.get_resource("Dealer").px->at(0)->point_value()))
			{
				// player wins
				m_rPlayers.get_resource(player_id).px->m_winner = true;
				//state_manager->change_state( Deal_State::instance(), game );
			}
			else 
			{
				// player loses
				m_rPlayers.get_resource(player_id).px->m_winner = false;
				//state_manager->change_state( Deal_State::instance(), game );
			}
			break;
		
		case 3: // double down?
			if (m_rHands.get_resource(player_id).px->at(m_rPlayers.get_resource(player_id).px->m_active_hand)->get_size() == 2)
			{
				//game->m_players[1].bet(game->m_players[1].m_bets[game->m_players[1].m_active_hand]);
				draw_card(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand, 0, 1);

				if( check_hand_value(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand,
					m_rHands.get_resource("Dealer").px->at(0)->point_value()))  
				{
					// player wins
					m_rPlayers.get_resource(player_id).px->m_winner = true;
					//state_manager->change_state( Deal_State::instance(), game );
				}
				else
				{
					// player loses
					m_rPlayers.get_resource(player_id).px->m_winner = false;
					//state_manager->change_state( Deal_State::instance(), game );
				}
			}
			else { break; }
		case 4:// split hand
			split_hand(player_id, m_rPlayers.get_resource(player_id).px->m_active_hand);
			break;	
		case 5: // fold
			// player loses
			m_rPlayers.get_resource(player_id).px->m_winner = false;
			//state_manager->change_state( Deal_State::instance(), game );
			break;
		default:// invalid entry
			std::cout << "Please enter 1 or 2.\n";
			break;
		}
	}
};
Here is the line of code causing the error:
int _tmain(int argc, _TCHAR* argv[])
{
	srand ( unsigned(time(NULL)) );
	Blackjack_Game * game = new Blackjack_Game();
	game->init();

	State_Manager state_manager;
	[b]state_manager.change_state( Menu_State::instance(), game );[/b]

	while ( state_manager.running() )
	{
		state_manager.update(game);
		state_manager.print(game);
		state_manager.handle_events(game);
	}

	game->cleanup();

	return 0;
}
And here is that function in detail, all the rest work pretty much the same:
void Gamestate::change_state(State_Manager * state_manager, Gamestate * state, Card_Game * game)
{
	state_manager->change_state(state, game);
}
Any ideas?

Share this post


Link to post
Share on other sites
Thanks very much, for some reason I thought I had tried that first and it didn't work and that's why I was posting, sorry to take up your time with a silly question!

But I have another question, lets say I wanted to make all the functions in the Card_Game class private except for the virtual functions, is it possible for me to do this and still write a turn_logic function for Blackjack_Game with those private functions?

Share this post


Link to post
Share on other sites
If they are private than derived classes won't be able to use them. If you want them available to derived classes but not visible to outside classes, make them protected.

Share this post


Link to post
Share on other sites

This topic is 3592 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this