For my CS Data Structures class, I am implementing a Generic Stack using linked list. However, I am getting “Redefinition of …. ” errors for all my constructors and functions in my .cpp file. The header file, “Stach.h”, was given by the instructor, and at the end she included “Stack.cpp”. Everything works fine when I comment out that line, but she wants it there.
Anybody ever heard of this?
Thanks guys,
David
The only time that I have included a
.cppfile is when I wanted to put the implementation of a template in a.cppfile so that my editor recognized it as C++ instead of C. Is the implementation of the stack a template?If it is, then the implementation of the template methods have to be available to compilation units that are using them. You usually use
.ippor.tccfor template implementation files if you are going to implement somewhere other than in the header itself. This is what Boost and a number of other libraries do. If this is the case, then you should not be compiling stack.cpp since the compiler will take care of that when your client or driver program includes the header file.