To compile template classes in g++ it is necessary for the .h file to include the .cxx file. Therefore, apvector.h includes apvector.cxx. Of course, the .cxx file that contains the implementation of a class always includes the .h file containing the interface of the class. Therefore, apvector.cxx also includes apvector.h. As a result, if you attempt to compile apvector.cxx by itself and produce an object file, like I did below, you get a large number of errors (the first few are shown below). This is because apvector.cxx includes apvector.h, which in turn includes apvector.cxx. So the compiler encounters the functions in apvector.cxx twice and complains about multiple definitions of the same function.
p-lnx203.cs.uiowa.edu% g++ -c apvector.cxx apvector.cxx:22: redefinition of `apvectorTo get around this, simply do not compile the file apvector.cxx explicitly. For example, testingAPVector.cxx is a program that uses the apvector class. So it includes apvector.h. Since apvector.h also includes apvector.cxx, when I compile testingAPVector.cxx as below, apvector.cxx also gets compiled and we get a correct executable program corresponding to testingAPVector.cxx.
::apvector()' apvector.cxx:22: `apvector ::apvector()' previously declared here apvector.cxx:22: no `apvector ::apvector()' member function declared in class `apvector ' apvector.cxx:33: redefinition of `apvector ::apvector(int)' apvector.cxx:33: `apvector ::apvector(int)' previously declared here apvector.cxx:33: no `apvector ::apvector(int)' member function declared in class `apvector '
p-lnx203.cs.uiowa.edu% g++ -o testingAPVector testingAPVector.cxx