Feb 28, 2017 at 4:04am UTC
Can somebody tell me why I keep getting an address when I run the length function? I don't have any of the other functions or even the list implemented but I thought that would mean it returns a 0 instead of an address.
class Vlist{
private:
class Node
{
public:
Node(Video *video, Node *next): videos(video), m_next(next)
{}
Video *videos;
Node *m_next;
};
Node *m_head;
public:
Vlist();
~Vlist();
void insert(Video *video);
void insert_sorted();
void print();
bool find();
bool remove();
int length();
};
Part of vlist.cpp
int Vlist:: length()
{
int size = 0;
Node *ptr = m_head;
while(ptr != NULL)
{
size++;
ptr = ptr -> m_next;
}
return size;
}
int main()
{
Vlist vlist;
string title, url, comment,command;
double length;
int rating;
while (getline(cin,command))
{
if (command != "length" && (command != "insert") && (command != "print") && (command != "lookup") && (command != "remove"))
{
cerr<< "<" << command << "> is not a legal command, giving up..." << endl;
return 1;
}
else if (command == "length")
{
vlist.length();
cout << length << endl;
}
else if (command == "insert")
{
}
else if (command == "print")
{
vlist.print();
}
else if (command == "lookup")
{
}
else if (command == "remove")
{
}
}
return 0;
}
I have an entire vlist.cpp and vlist.h file if needed. I'm not really sure where to locate the problem.
Last edited on Feb 28, 2017 at 4:06am UTC
Feb 28, 2017 at 6:51am UTC
Ah okay thank you so much!