Xnyper
April 6th, 2008, 06:36 AM
I am working on a programming assignment and I could really use some help. I don't want anybody to do this for me, I just need a nudge...
I would like to go back through some previous sections and re-learn templates, because I think that my problem lies with them--but I have only 24 hours to fix this, and tomorrow is a work day :-/
I am asked to write a definition for the copy constructor for the class queueType. I also need to overload the assignment operator, but once I have the constructor done, that part is cake.
In the book, there is a simmilar class, stackType, with the copy constructor already defined. I looked at that copy constructor for my inspiration here, and understood it for the most part. the only part that I didn't understand is the first line, which read:
delete [] list;
This line does not seem to be causing my problem (outlined below) but I thought I would mention it so that when you see my comments that say "I don't really understand this line" you will see why it is there. I'd love to understand why it is in there, but that is secondary to my need to finish this program.
The only way that the copy constructor that I referenced above differs from the one that I need to write is in the way it walks through the list. the one mentioned above directly accessed the array, which I understand, but the array I need to copy is circular (that is % maxQueueSize) which is where I run into trouble.
The algorithm I am using now was adapted from the one used in the book's test program, testProgFromBook.cpp. Iit works great for stepping through a queue and printing its contents, but it is either invalid for assigning those contents to a new array, I am running into scope issues, or I have made some sort of template faux pas.
Attatched are 5 files, below are their explanations:
queueADT.h this file is the header file for the "queue" class. It was provided to me so that I could #include it, but I do not need to modify it in any way.
queueAsArray.h this file is the header file for the class that I need to modify. For the most part it too does not need to be modified. The last few functions, however, were left empty for me to fill in. You should notice the difference between my work and the pre-done work.
queueAsArray.h.bak this is a copy of the header file for the class that I need to modify before I started playing with it--in case you want to see how it was before I messed it up
testProgFromBook.cpp this was provided by the book to test the book's class, I didn't touch it
testProgIModified.cpp I edited the above file so that it would test the copy constructor that I needed to define in queueAsArray.h
Now, as far as I can tell, testProgIModified.cpp fails to compile because of one error on line 36
the error on line 36, I think, is caused by an error on line 198 of queueAsArray.h
The compiler tells me:
queueAsArray.h:198: error: passing ‘const queueType<int>’ as ‘this’ argument of ‘void queueType<Type>::deleteQueue() [with Type = int]’ discards qualifiers
testProgFromBook.cpp compiles and runs just fine. It does not call the constructor in question, but it does include the header file in question--so the problem is not one of syntax.
I am not entirely sure that my constructor is doing its job correctly, but if I could get it to compile I think I would be well on my way to getting it working right.
Thank you very much for anything you can do--I really appreciate it!
I would like to go back through some previous sections and re-learn templates, because I think that my problem lies with them--but I have only 24 hours to fix this, and tomorrow is a work day :-/
I am asked to write a definition for the copy constructor for the class queueType. I also need to overload the assignment operator, but once I have the constructor done, that part is cake.
In the book, there is a simmilar class, stackType, with the copy constructor already defined. I looked at that copy constructor for my inspiration here, and understood it for the most part. the only part that I didn't understand is the first line, which read:
delete [] list;
This line does not seem to be causing my problem (outlined below) but I thought I would mention it so that when you see my comments that say "I don't really understand this line" you will see why it is there. I'd love to understand why it is in there, but that is secondary to my need to finish this program.
The only way that the copy constructor that I referenced above differs from the one that I need to write is in the way it walks through the list. the one mentioned above directly accessed the array, which I understand, but the array I need to copy is circular (that is % maxQueueSize) which is where I run into trouble.
The algorithm I am using now was adapted from the one used in the book's test program, testProgFromBook.cpp. Iit works great for stepping through a queue and printing its contents, but it is either invalid for assigning those contents to a new array, I am running into scope issues, or I have made some sort of template faux pas.
Attatched are 5 files, below are their explanations:
queueADT.h this file is the header file for the "queue" class. It was provided to me so that I could #include it, but I do not need to modify it in any way.
queueAsArray.h this file is the header file for the class that I need to modify. For the most part it too does not need to be modified. The last few functions, however, were left empty for me to fill in. You should notice the difference between my work and the pre-done work.
queueAsArray.h.bak this is a copy of the header file for the class that I need to modify before I started playing with it--in case you want to see how it was before I messed it up
testProgFromBook.cpp this was provided by the book to test the book's class, I didn't touch it
testProgIModified.cpp I edited the above file so that it would test the copy constructor that I needed to define in queueAsArray.h
Now, as far as I can tell, testProgIModified.cpp fails to compile because of one error on line 36
the error on line 36, I think, is caused by an error on line 198 of queueAsArray.h
The compiler tells me:
queueAsArray.h:198: error: passing ‘const queueType<int>’ as ‘this’ argument of ‘void queueType<Type>::deleteQueue() [with Type = int]’ discards qualifiers
testProgFromBook.cpp compiles and runs just fine. It does not call the constructor in question, but it does include the header file in question--so the problem is not one of syntax.
I am not entirely sure that my constructor is doing its job correctly, but if I could get it to compile I think I would be well on my way to getting it working right.
Thank you very much for anything you can do--I really appreciate it!