Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-07-2004, 09:17 AM   #31 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Quote:
Originally posted by Valmont
Service Pack 5?
Dont know how to check??
dirs is offline   Reply With Quote
Old 05-07-2004, 09:25 AM   #32 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Try my workaround wich I posted before your post. I am just gambling but it solves many bugs.

goto help->about msvc (or something like that for info about your ide)
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 09:33 AM   #33 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Quote:
Originally posted by Valmont
Try my workaround wich I posted before your post. I am just gambling but it solves many bugs.

goto help->about msvc (or something like that for info about your ide)
already donethat!
just says vc ++ 6.0 and product id.
I am installing service pack 5 now
dirs is offline   Reply With Quote
Old 05-07-2004, 09:37 AM   #34 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Well, how did it react when you did my workaround?
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 09:49 AM   #35 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Quote:
Originally posted by Valmont
Well, how did it react when you did my workaround?
Where should I put
typedef vector<pair<int,int> > VPairs;
VPairs Deck; ??
dirs is offline   Reply With Quote
Old 05-07-2004, 09:53 AM   #36 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Quote:
Originally posted by dirs
Where should I put
typedef vector<pair<int,int> > VPairs;
VPairs Deck; ??
I put it under card.h before the class card starts and i got 7 errors??
c:\blackjack\card.h(51) : error C2040: 'i' : 'struct std::pair<int,int> *' differs in levels of indirection from 'int'
c:\blackjack\card.h(51) : error C2446: '!=' : no conversion from 'struct std::pair<int,int> *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\blackjack\card.h(51) : error C2040: '!=' : 'int' differs in levels of indirection from 'struct std::pair<int,int> *'
c:\blackjack\card.h(54) : error C2100: illegal indirection
c:\blackjack\card.h(54) : error C2228: left of '.first' must have class/struct/union type
c:\blackjack\card.h(54) : error C2100: illegal indirection
c:\blackjack\card.h(54) : error C2228: left of '.second' must have class/struct/union type
Error executing cl.exe.

Main.exe - 7 error(s), 0 warning(s)
dirs is offline   Reply With Quote
Old 05-07-2004, 09:58 AM   #37 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Copy and paste the code below. It is complete so remove what you have now (in card.h).

Code:
#ifndef CARD_H
#define CARD_H

#include <iostream>
#include <vector>

using namespace std; 

class Card
{
public:
	Card();
public:
	// Observe the naughty space between > > !
	typedef vector<pair<int,int> > VPairs;
	VPairs Deck;
	VPairs GetDeck()
	{
		return Deck;
	}
	
private:
	enum { Club, Spade, Diamond, Heart} suit;
	
};

Card::Card()
{
	int cardtype;
	for (int i = 0; i < 52; i++)
	{
		// First 13 cards are spades, next 13 are diamonds etc.
		cardtype = i/13;
		switch(cardtype)
		{
			case 0: suit = Club;	break;
			case 1: suit = Spade; break;
			case 2: suit = Diamond; break;
			case 3: suit = Heart; break;
		}
		Deck.push_back(pair<int, int>(suit, 2+i%13));
	}

	//Demonstration of how to iterate through a "vector" holding "pair" objects.
	//It is only one more methods. See "void CardGames::Shuffle()" for the second
	//way of iterating through the vector. 
	for(VPairs::iterator i = Deck.begin(); i != Deck.end(); ++i)
	
	{
		cout<< (*i).first <<" "<< (*i).second<<endl;
	}

} 

#endif //CARD_H
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 10:02 AM   #38 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Tried the code u sent now still same errors!
c:\blackjack\card.h(47) : error C2040: 'i' : 'struct std::pair<int,int> *' differs in levels of indirection from 'int'
c:\blackjack\card.h(47) : error C2446: '!=' : no conversion from 'struct std::pair<int,int> *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
c:\blackjack\card.h(47) : error C2040: '!=' : 'int' differs in levels of indirection from 'struct std::pair<int,int> *'
c:\blackjack\card.h(50) : error C2100: illegal indirection
c:\blackjack\card.h(50) : error C2228: left of '.first' must have class/struct/union type
c:\blackjack\card.h(50) : error C2100: illegal indirection
c:\blackjack\card.h(50) : error C2228: left of '.second' must have class/struct/union type
Error executing cl.exe.

Main.exe - 7 error(s), 0 warning(s)
dirs is offline   Reply With Quote
Old 05-07-2004, 10:32 AM   #39 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Yes, erm, what I expected. VC6 doesn't support closing of ranges for
variables declared at the beginning of a for statement.

There is a workaround, but I can't test it probably since I don't want to install vc6 (I use 7).
Anyway, change your "print" code and see what happens, in the mean time I'll wait for a friend of mine for your problem:

Code:
VPairs::iterator i = Deck.begin();
	for(; i <= Deck.end(); ++i)	
	{
		cout<< (*i).first <<" "<< (*i).second<<endl;
	}
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 10:35 AM   #40 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
OMG ROFL
wait!!!
change the i's to j's.!!!
Code:
VPairs::iterator j = Deck.begin();
	for(; j <= Deck.end(); ++j	)
	{
		cout<< (*j).first <<" "<< (*j).second<<endl;
	}
On new compilers it doesn't bother but on old(er) it does. LOL.
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 10:50 AM   #41 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
Quote:
Originally posted by Valmont
OMG ROFL
wait!!!
change the i's to j's.!!!
Code:
VPairs::iterator j = Deck.begin();
	for(; j <= Deck.end(); ++j	)
	{
		cout<< (*j).first <<" "<< (*j).second<<endl;
	}
On new compilers it doesn't bother but on old(er) it does. LOL.
It works now!! Great!!
dirs is offline   Reply With Quote
Old 05-07-2004, 11:10 AM   #42 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Hahaha, the original code was std C++ correct but VC doesn't support it. I made this lil mistake a giga-gazillion times and still fall for it...
I needed to re-think the whole situation going on here!
ROFLMAO.

You can put back the
Code:
VPairs::iterator j = Deck.begin()
in the for-loop as well most likely.
You you can change (*). to -> most likely as well.
But leave the typedef intact.
__________________
Valmont is offline   Reply With Quote
Old 05-07-2004, 11:18 AM   #43 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
That worked as well!
I will try to do the rest of coding !
Thanks
dirs is offline   Reply With Quote
Old 05-07-2004, 12:34 PM   #44 (permalink)
dirs
Registered User
 
Join Date: May 2004
Posts: 40
dirs is on a distinguished road
In The function BlackJack::Shuffle(vector<pair<int,int> > cards)
cout<<cards[i].first<<"_"<<cards[i].second<<endl;
shouldn't it print out the shuffeled deck.
i get
0 2
0 2
all the time instead.
dirs is offline   Reply With Quote
Old 05-07-2004, 01:43 PM   #45 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Insert
Code:
srand( (unsigned)time( NULL ) );
in the Shuffle method, between "int k" and the "for" loop.
Code:
void BlackJack::Shuffle(vector<pair<int,int> > cards)
{
	pair<int, int> temp;
	int k;
	srand( (unsigned)time( NULL ) );
	for (unsigned int i = 0; i < cards.size(); ++i)
	{
		k=(rand() % 52);
		temp = cards[i];
		cards[i] = cards[k];
		cards[k] = temp;

      // A simple but ugly test. Friends are "helping" me (not)
		//so I need to go soon :(.
		cout<<cards[i].first<<"_"<<cards[i].second<<endl;
	}	
}
Since we are working in std c++, add the <ctime> header on top.
Not <time.h> but <ctime> . If you read a few topics in this forum you will know why.
The "c" word without the ".h" extension is the new standard C++ of adding an 'old' C-based library.
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to put data methods inside class or not? sde Java 2 05-25-2004 04:09 PM
pointer to function with class? Kportertx Standard C, C++ 5 04-11-2003 05:12 AM
class theory sde PHP 2 01-11-2003 12:48 PM


All times are GMT -8. The time now is 03:59 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting