一个小小的结构体问题??——改来改去都跟书的的例题一样了还是不行
#include <iostream>using namespace std;
struct BitCards
{
unsigned face : 4;
unsigned suit : 2;
unsigned color :1;
};//定义一张牌
class DeckOfCards
{
public:
DecdOfCards();/*初始化一副牌*/
void shuffle();//洗牌函数
void deal();/*发牌小函数*/
private:
BitCards cards[52];/*定义52张牌*/
};
DeckOfCards::DecdOfCards()
{
for( int i=0;i<52;i++)
{
cards[i].face=i%13;
cards[i].suit=i/13;
cards[i].color=i/26;
cout<<"kan"<<cards[i].face;
}
}
void DeckOfCards::shuffle()
{
for(int i=0; i<52; i++)
{
int j=rand()%52;
BitCards temp;
temp=cards[j];
cards[j]=cards[i];
cards[i]=temp;
}
}
void DeckOfCards::deal()
{
for(int i=0;i<52;i++)
{
cout<<"\t\t"<<cards[i].face<<" of "
<<cards[i].suit<<"\t\t";
if(i%2==0)
cout<<endl;
}
}
void main()
{
DeckOfCards test;
// test.shuffle();
// test.deal();
}