C++ 使用链表函数时遇到问题
我在使用指向视频对象的指针的成员函数时遇到问题。 我的代码如下: 清单h:C++ 使用链表函数时遇到问题,c++,pointers,linked-list,C++,Pointers,Linked List,我在使用指向视频对象的指针的成员函数时遇到问题。 我的代码如下: 清单h: 5 #ifndef VLIST_H 6 #define VLIST_H 7 8 #include<iostream> 9 using namespace std; 10 11 #include<string> 12 #include"video.h" 13 14 class Vlist 15 { 16 public: 17 Vlist(); 18 // ~Vlist();
5 #ifndef VLIST_H
6 #define VLIST_H
7
8 #include<iostream>
9 using namespace std;
10
11 #include<string>
12 #include"video.h"
13
14 class Vlist
15 {
16 public:
17 Vlist();
18 // ~Vlist();
19 void insert(Video *vid);
20 // void insert_alphabetical(Video *vid);
21 void print();
22 // void length();
23 bool lookup(string title);
24 bool remove(string title);
25 private:
26 class Node
27 {
28 public:
29 Node(Video *vid, Node *next)
30 {m_vid = vid; m_next = next;}
31 Video *m_vid;
32 Node *m_next;
33 };
34 Node *m_head;
35 };
36
37 #endif
5#ifndef VLIST#H
6#定义列表
7.
8#包括
9使用名称空间标准;
10
11#包括
12#包括“video.h”
13
14级列表
15 {
16公众:
17 Vlist();
18//~Vlist();
19无效插入(视频*视频);
20//void insert_字母顺序(视频*视频);
21无效打印();
22/空隙长度();
23布尔查找(字符串标题);
24 bool删除(字符串标题);
25私人:
26类节点
27 {
28公众:
29节点(视频*视频,节点*下一个)
30{m_vid=vid;m_next=next;}
31个视频*m_vid;
32节点*m_下一步;
33 };
34节点*m_头;
35 };
36
37#endif
vlist.cpp:
5 #include<iostream>
6 using namespace std;
7
8 #include<string>
9 #include"vlist.h"
10 #include"video.h"
11
12 Vlist::Vlist()
13 {
14 m_head = NULL;
15 }
16
17 void Vlist::insert(Video *vid)
18 {
19 m_head = new Node(vid, m_head);
20 }
21
22 void Vlist::print()
23 {
24 Node *ptr = m_head;
25 while(ptr != NULL)
26 {
27 cout << ptr->m_vid->print();
28 ptr = ptr->m_next;
29 }
30 }
5#包括
6使用名称空间标准;
7.
8#包括
9#包括“vlist.h”
10#包括“video.h”
11
12 Vlist::Vlist()
13 {
14米水头=零;
15 }
16
17无效列表::插入(视频*视频)
18 {
19 m_头=新节点(vid,m_头);
20 }
21
22无效列表::打印()
23 {
24节点*ptr=m_头;
25 while(ptr!=NULL)
26 {
27 cout m_vid->print();
28 ptr=ptr->m_next;
29 }
30 }
视频.h:
5 #ifndef VIDEO_H
6 #define VIDEO_H
7
8 #include<iostream>
9 using namespace std;
10
11 #include<string>
12
13 class Video
14 {
15 public:
16 Video(string title, string url, string comment,float length, int rating);
17 ~Video();
18 void print();
19
20 private:
21 string m_title;
22 string m_url;
23 string m_comment;
24 float m_length;
25 int m_rating;
26 };
27
28 #endif
5\ifndef视频
6.定义视频
7.
8#包括
9使用名称空间标准;
10
11#包括
12
13课视频
14 {
15公众:
16视频(字符串标题、字符串url、字符串注释、浮点长度、整数评级);
17~视频();
18无效打印();
19
20私人:
21字符串m_标题;
22字符串m_url;
23字符串m_注释;
24个浮球长度;
25国际货币单位评级;
26 };
27
28#endif
Video.cpp:
5 #include<iostream>
6 using namespace std;
7
8 #include<string>
9
10 #include "video.h"
11
12 using namespace std;
13
14 Video::Video(string title, string url, string comment, float length, int rating)
15 {
16 m_title = title;
17 m_url = url;
18 m_comment = comment;
19 m_rating = rating;
20 m_length = length;
21 }
22
23 /* Video::~Video()
24 {
25 cout << "object is desructing" << endl;
26 } */
27
28 void Video::print()
29 {
30 cout << m_title << ", " << m_url << ", " << m_comment << ", " << m_length << ", ";
31 for(int i = 0; i < m_rating; i++)
32 {
33 cout << "*";
34 }
35 cout << endl;
36 }
37
5#包括
6使用名称空间标准;
7.
8#包括
9
10#包括“video.h”
11
12使用名称空间标准;
13
14视频::视频(字符串标题、字符串url、字符串注释、浮点长度、整数分级)
15 {
16 m_title=标题;
17 m_url=url;
18 m_注释=注释;
19 m_评级=评级;
20米长=长度;
21 }
22
23/*视频::~Video()
24 {
25 coutVList::print()
无效,不能传递到cout
更新:
cout << ptr->m_vid->print();
cout << ptr->m_vid->print();
ptr->m_vid->print();