Reputation: 53
vlist.h
class Vlist
{
public:
Vlist();
~Vlist();
void insert(string title, string URL, string comment, float length, int rating);
bool remove();
private:
class Node
{
public:
Node(class Video *Video, Node *next)
{m_video = Video; m_next = next;}
Video *m_video;
Node *m_next;
};
Node* m_head;
};
main.cpp
int main()
{
....blah blah.... (cin the values)
Array[i] = new Video(title, URL, comment, length, rating);
Vlist objVlist;
objVlist.insert(title, URL, comment, length, rating);
}
vlist.cpp
This is where the error comes from
(m_head = new Node(Video, NULL);
... the job of this function is to insert a pointer to an object from class video into the list.
void Vlist::insert(string title, string URL, string comment, float length, int rating)
{
Node *ptr = m_head;
//list is empty
if(m_head == NULL)
m_head = new Node(Video, NULL);
else
{
ptr = ptr->m_next;
ptr = new Node(Video, NULL);
}
//sort the list every time this executes
}
video.h
This is the class i am trying to point to using the linked lists.
class Video
{
public:
Video(string title, string URL, string comment, float length, int rating);
~Video();
void print();
bool longer(Video *Other);
bool higher(Video *Other);
bool alphabet(Video *Other);
private:
string m_title;
string m_url;
string m_comment;
float m_length;
int m_rating;
};
first time using stack overflow, not too sure what will happen.
Upvotes: 0
Views: 269
Reputation: 454
Try to change
m_head = new Node(Video, NULL);
to
m_head = new Node(new Video(title, URL, comment, length, rating), NULL);
and this:
else
{
ptr = ptr->m_next;
ptr = new Node(Video, NULL);
}
is not really the right way to add a new Node
to the head of the list. Need something like:
ptr = new Node(new Video(title, URL, comment, length, rating), NULL);
ptr->m_next = m_head;
m_head = ptr;
Upvotes: 2
Reputation: 66371
"Video" is the name of a class.
You need to create a Video
instance.
void Vlist::insert(string title, string URL, string comment, float length, int rating)
{
Video* v = new Video(title, URL, comment, length, rating);
Node *ptr = m_head;
if(m_head == NULL)
m_head = new Node(v, NULL);
else
{
ptr = ptr->m_next;
ptr = new Node(v, NULL);
}
// ...
}
Upvotes: 1