I am pretty sure I have something wrong with how I am using my templates like syntax. I am making a program that works with an array-based Queue. I might have had this issue before but I can't remember what it was I fixed.
I just put everything in a namespace because it wasn't before, but now it's back to this linker error. The first one is either from my default or parameterized or copy constructor, and then it goes down from there. I only put the first 3 functions. Actually I am also going to paste this into replit to make sure it's not just my compiler...
I also noticed I only have errors with my public functions.
Function templates and member functions of class templates need to be defined in the same translation unit where they get used. Therefore you normally see them defined in the header.
Wait so I declare and define my templates all in arrayqueue.h ? I understand the format/parameters need to match for templates too, so I am not sure I need another "<ItemType>" when I wrote "operator=(const ArrayQueue<ItemType>& right)", but it seemed to accept it.
Wait so I declare and define my templates all in arrayqueue.h ?
Yes. The compiler can't generate the code for the template until it knows the template parameter class. That means it needs to know the declaration and the definition whenever you use the template.
Right, so in a header file the template should be in the right format, and then the implement file should also match. I guess I should mention the files shown are header, implement, and main, from top to bottom. I am not seeing where I messed up.
You're messing up by having an "implementation" (.cpp) file for a class template. Move everything from your ArrayQueue.cpp into the bottom of ArrayQueue.h. Delete ArrayQueue.cpp.
And I assume this is just a copy-paste error, but you are missing the } and have an extraneous #endif in your second file excerpt.
Ya I am pretty confused now, because I looked at my past template assignments and I did all of this. Including a .cpp into my header (I know I should not do this now) I then defined the templates in the .cpp. So I don't even know what I did to get the previous ones to compile.
Including a .cpp into my header (I know I should not do this now) I then defined the templates in the .cpp
That's actually one of the few times when people will #include a .cpp file. But personally I don't see the point; it's just extra time/effort to split it when it eventually gets recombined anyway.