gpt4 book ai didi

c++ - 为什么我愚蠢的纸牌游戏类(class)不能互相交谈?

转载 作者:太空宇宙 更新时间:2023-11-04 15:42:48 25 4
gpt4 key购买 nike

<分区>

我曾尝试在这里制作某种纸牌游戏,但持有人/纸牌堆的类(class)不会将正确的东西赠送给接收者/玩家,我不知道如何解决这个问题。

程序如下:

 #include <iostream>

using namespace std;

class subclass // like a card
{
public:
subclass();
subclass(int x);
int nummer;
int getnummer();
};

subclass::subclass():nummer(0){}
subclass::subclass(int x):nummer(x){}
int subclass::getnummer()
{
return nummer;
}

持有人类别:

 class holder // like a cardpile
{
public:
holder();
subclass cardpile[2];
subclass* pile; // a cardpile which has 2 cards, with nummber 1 and 2.
subclass* getsubclass(int i); // take first or second card.
};
holder::holder()
{
subclass first(1*3);
subclass second(2*3);
pile=cardpile;
pile=&first;
pile++;
pile=&second;
pile--;
}

subclass* holder::getsubclass(int i) //1 eller 2.
{
return pile+i;
}

接收者类/玩家

 class reciver // like a player
{
public:
subclass part_of_holder;
reciver();
void getsubclass( subclass* in); // give this card to player from this pointer
void showinside(); // what card do player have
};

reciver::reciver():part_of_holder(){}

void reciver::getsubclass( subclass* in)
{
part_of_holder=*in;
}
void reciver::showinside() // what card do player have
{
cout<< part_of_holder.getnummer();
}

主要的

   int main()
{
holder cardpile;
reciver player;

cout << "first card should be 1*3 and it is : " ;
player.getsubclass(cardpile.getsubclass(0));
player.showinside();
cout << endl <<"first card should be 2*3 and it is : " ;
player.getsubclass(cardpile.getsubclass(1));
player.showinside();

return 0;
}

最后得到的都是废话

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com