PlasmaZero
Programmer
I've looked around, and can't seem to find a good tutorial for writing custom collection classes. As part of a project involving music, I'm attempting to create a collection of Note objects (Note being a custom class of mine). From what I could understand of the info at msdn.microsoft.com, I created this, but it won't work:
#include <afxtempl.h>
*snip*
class Notes
{
Notes();
~Notes();
public:
void Add(Note note){
noteList.AddHead(Note note);
}
void Remove(int index){
if (index > Count - 1 || index < 0)
throw new Exception("Index out of bounds");
noteList.RemoveAt(noteList.FindIndex(index));
}
void Insert(int index, Note note) {
noteList.InsertBefore(noteList.FindIndex(index), Note note);
}
Note Item(int Index) {
if (!noteList.IsEmpty())
return (Note) noteList.GetAt(noteList.FindIndex(Index));
else
return null;
}
private:
CList<Note, Note> noteList;
};
So, I'd appreciate it if anyone can help me out here. I only need basic functionality really - Add, Remove, Insert, GetAt...
Thanks
#include <afxtempl.h>
*snip*
class Notes
{
Notes();
~Notes();
public:
void Add(Note note){
noteList.AddHead(Note note);
}
void Remove(int index){
if (index > Count - 1 || index < 0)
throw new Exception("Index out of bounds");
noteList.RemoveAt(noteList.FindIndex(index));
}
void Insert(int index, Note note) {
noteList.InsertBefore(noteList.FindIndex(index), Note note);
}
Note Item(int Index) {
if (!noteList.IsEmpty())
return (Note) noteList.GetAt(noteList.FindIndex(Index));
else
return null;
}
private:
CList<Note, Note> noteList;
};
So, I'd appreciate it if anyone can help me out here. I only need basic functionality really - Add, Remove, Insert, GetAt...
Thanks