C++ C++;连接的2个类的动态链接列表(RPG系统)
我目前正在为UNI work开发一个RPG系统,并且我在将两个类链接在一起的最有效形式上遇到了问题,因为创建者角色将能够使用已创建的项——代码目前以动态链接列表的形式存在C++ C++;连接的2个类的动态链接列表(RPG系统),c++,oop,reference,C++,Oop,Reference,我目前正在为UNI work开发一个RPG系统,并且我在将两个类链接在一起的最有效形式上遇到了问题,因为创建者角色将能够使用已创建的项——代码目前以动态链接列表的形式存在 我有两节课 Character itemtype class item { string itemtype string itemname void item_search(item* ihead, item* &ipast, item* &icurrent) { s
我有两节课
Character
itemtype
class item
{
string itemtype
string itemname
void item_search(item* ihead, item* &ipast, item* &icurrent)
{
string search;
if (ihead==NULL)
{
cout<<"no item"<<endl;
}
else
{
cout<<"Enter item to serach for :"<<endl;
getline(cin,search);
icurrent=ihead; //current pointer goes to -> header
cout<<icurrent<<" "<<search<<" "<<icurrent->itemtype<<endl;
while(icurrent!=NULL && search>icurrent->itemname)
{
cout<<"Item Type:"<<icurrent->itemtype<<" "<<cout<<icurrent->itemname<<endl;
ipast=icurrent; //Past = new current pointer
icurrent=icurrent->inext; //current pointer = next pointer
}
}
}
public:
item()
{
cout<<"Enter Item Type: "<<endl;
getline(cin,itemtype);
cout<<"Enter Item Name: "<<endl;
getline(cin,itemname);
cout<<"Enter Item Description: "<<endl;
}
};
class character
{
string charactername
}
字符
实体类型
类项目
{
字符串项类型
字符串itemname
无效项目搜索(项目*ihead、项目*&ipast、项目*&icurrent)
{
字符串搜索;
如果(ihead==NULL)
{
你想让每个项目都有一个对应的字符与之关联吗?为什么不让项目类的成员变量有一个指向字符类的指针呢?@bearsmahoney我不太清楚你的意思?我基本上是想找出一种方法,让字符指向链接列表的itemheader。当一个新项目创建并添加到播放机它将检查列表中是否有任何其他实例,然后添加一个标题为=的项目到第一个项目的页脚,并且当前项目的结尾变为空?我没有意义,对不起,我太困惑了。下面是一个我得到的示例。我真的不确定w你的总体目标是什么。从架构上考虑,物品真的需要知道它属于什么角色吗?我不这么认为。看起来更重要的关系是角色确切地知道它持有什么物品。在这种情况下,我建议每个角色都有一个数组或向量(某种集合)指向项的指针。