链接列表问题C ++ ...我们可以在一个程序中制作两个不同的节点类型吗? [英] LINKED LIST question C++ ...Can we make TWO different node types in one program?

查看:35
本文介绍了链接列表问题C ++ ...我们可以在一个程序中制作两个不同的节点类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要完成另一个有关链表的项目.我想知道是否有可能用两个struct节点类型代码编写来创建两个节点.如果是这样,我应该如何放置它们?我的代码将包含一个节点类型,并在列表中包含视频".另一个节点类型在列表中带有客户"详细信息.

I have another project to finish off regarding linked lists. I wanted to know if it was possible to write in TWO struct nodetype codes to create two nodes. If so how and where should I place them? My code is going to contain of one node type with "Videos" in a list. And another node type with "Customer" details in a list.

我计划将功能用于将要使程序执行的所有其他操作.我想知道制作两个节点的代码,以及当我为它们专门创建功能时如何指定这些节点的方式和位置?(例如,为视频节点插入新视频,为客户节点插入视频(表明他们已租用)视频)等).

I plan to use functions for every other operation I will enable for the program to do. I wanted to know the code for making two nodes and how and where I should specify these nodes when I make functions specifically for them?(such as inserting a new video for the video node and inserting a video for customer node(showing that they rented the video) etc etc)...

有人可以解释代码的详细信息,以便我理解吗?

Can someone please explain the code's details so I can understand it?

推荐答案

由于类模板的实例化会产生新的类型,因此可以将列表节点设为模板:

Because an instantiation of a class template yields a new type, you can make your list node a template:

template<class Tag>
struct ListNode
{
    ListNode *prev, *next;
};

然后从同一模板多次导出,并使用不同的标记类型实例化它:

And then derive multiple times from the same template instantiating it with a different tag type:

struct VideoTag;
struct CustomerTag;

struct Item 
    : ListNode<VideoTag>
    , ListNode<CustomerTag> 
{};

这篇关于链接列表问题C ++ ...我们可以在一个程序中制作两个不同的节点类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆