What is wrong with my code?
I can't figure it out.
It compiles when I declare a QueueTp object but when I try to use the member function enqueue, it does not compile anymore.
I put the code on one page above but actually it is in 3 files, the main file, a secondary file and .h file.
The error I get is:
Undefined symbols for architecture x86_64:
"QueueTp<int>::enqueue(int const&)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I emptied my function dequeue and I still get the same error. So it is not something in the code of the function. Very strange!
I put the definition of my functions in my main file and now it compiles. I don't understand why the files are not linked properly when I put them in the separate file. I have done it many times before.
I found what the problem is!
I can't put my member function definitions for the template class QueueTp in a separate .cpp file, I must put them in the .h file of QueueTp or in main.cpp.
According to the book C++ primer, the reason is that the template member functions are not really member functions but instructions to the compiler on how to generate member functions for a particular instantiation.