hi
I have this projct for school and its kind of a long code so I'll just put the code here to what i think its pertinent.
So i create an instance of todoui and call the function run:
driver.cpp
1 2 3
TodoUI* ui = new TodoUI;
if (argc == 1)
ui->run();
from that code lets see the todoui constructor:
todoui.cpp
1 2 3 4
TodoUI::TodoUI()
{
TodoList* list = new TodoList;
}
it creates an instance of todolist, heres the constructor for that:
1 2 3 4 5 6 7
TodoList::TodoList()
:capacity(25), size(0)
{
items = new TodoItem*[capacity];
for (int i = 0; i < capacity; i++)
items[i] = NULL;
}
and heres the constructor for todoitem just in case:
todoitem.cpp
ok so now that that is setup lets see where list is pointing to:
todoui.cpp cout << list;
the output for that is 0 which means its not pointing anywhere...
shouldnt it be pointing to a todolist object?
please help... i have no idea what is wrong. it was working and then i added something and it stopped working but i dont remember exactly what it was :(
It would be nice to see the header files, but I assume that class TodoUI has a member variable "list". In the constructor of TodoUI you declare a local variable
TodoList* list = new TodoList;,
which hides the class member variable. Therefore, the member variable is not initialized. You should write
another question, here are the instructions on the foofile:
1 2 3 4 5 6 7 8 9 10 11
/**
* Load the contents of a file into a dynamic array of dynamic TodoItem objects.
* Each line of the file is assumed to be an entry for a single TodoItem, formatted
* in the following way -> TEXT@PRIORITY@COMPLETED. FooFile does <b>not</b> free
* the dynamic memory associated with the objects or the array. The caller must free
* this memory.
* @param filename the name of the file to load
* @param count will be set to the number of TodoItem loaded
* @return a dynamic array of dynamic TodoItem objects
*/
static TodoItem** load (string filename, int& count);
how would I use that? the way i have it is not working :(
Did you fix the second similar mistake in todoui.cpp line 10 (also pointed out by bluecoder)?
If not - remove the declaration and see if it works better.