わかりました、助けてくれてありがとう
gamemanager.h」
#include "item.h"
#include "hero.h"
class gamemanager
{
public:
void acquireItems(hero player, item vendor);
};
gamemanager.cpp:
void gamemanager::acquireItems(hero player, item vendor)
{
int choice;
int choice2;
cout<<"\nWould you like to buy 1.offense OR 2.defense : ";
cin>>choice;
if(choice==1)
{
cout<<"\nGood day sir, what can i do for you: \n1.Buy\n2.Sell\n3.Leave \n";
cin>>choice2;
if(choice2==1)
{
cout<<"\nThese are my wares today: "<<endl;
int index;
int select;
int wep;
char sel;
index=rand()%vendor.Wname.size();
if(index==0)
++index;
for(wep=0; wep<index; wep++)
{
select = rand()%vendor.Wname.size();
cout<<wep<<". "<<vendor.Wname[select]<<endl;
}
cout<<"\nEnter the number of item you want, or enter 'q' to exit"<<endl;
cin>>sel;
if(sel=='q')
return;
weapon* WEAPON = new weapon(vendor.Wname[wep]);
player.inventory.push_back(WEAPON);
player.setdefense();
}
}
ヒーロー.h
class hero
{
public:
vector<item*> inventory;
void setdefense();
};
ヒーロー.cpp
void hero::setdefense()
{
if(inventory.size()!=0)
{
for(unsigned int x=0; x<inventory.size(); x++)
{
m_defense = m_defense + inventory[x]->getbonus();
}
}
}
主要():
#include <iostream>
#include "gamemanager.h"
#include "hero.h"
#include "enemy.h"
#include "item.h"
int main()
{
gamemanager boss;
item vendor;
hero player(10, 20);
boss.acquireItems(player, vendor);
cout<<player.inventory.size()<<endl;
return 0;
}
クラスには明らかにもっと多くのものがありますが、サイズのために、私は無関係なものを取り出しました。そして、main() で在庫サイズを数えたときに言ったように、ゼロを出力します。また、プレイヤーは main() で作成されたクラス hero のインスタンスです