passing parameters
-
I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }
-
I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }
Well, you didn't say where the error is happening, so I can only guess:
template<class recordType>
void insert(const recordType &entry)Take out the redundant template there, you only need that if the method has different template params than the class that it's in. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Actual sign at the laundromat I go to: "No tinting or dying."
-
Well, you didn't say where the error is happening, so I can only guess:
template<class recordType>
void insert(const recordType &entry)Take out the redundant template there, you only need that if the method has different template params than the class that it's in. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Actual sign at the laundromat I go to: "No tinting or dying."
sorry about not being more specific, but it seems to not like the way I am sending the parameter in the void main(). I will try your method and see what happends. thanks. Also when I double-click on the error, it goes directly to the find_index() call in the insert function. Such as: see the comment below.
void main()
{
table ta;
tractor t;
t.key=44;
ta.insert(t); // this line seems to be generating the errors.}
-
I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }
In searching Google, I actually found code very similar to this except they pass entry.key by value instead of taking address:
find_index(entry.key,already_present,index);
You probably just made a typo. -
In searching Google, I actually found code very similar to this except they pass entry.key by value instead of taking address:
find_index(entry.key,already_present,index);
You probably just made a typo.