C++ template blues
It's been a while since I've programmed for school, and after picking up a copy of Sedgewick I decided to try out one of the problems for kicks. The class I wrote works great for concrete types, but when I tried to make a templated version I couldn't get it to link, as it couldn't resolve function calls to the templated class. Here's a stripped down version of the example.
Here's the makefile: Code:
exe=polyadd Code:
polyadd.o: In function `main': Code:
/** polynomial.h */ Code:
/** polynomial.c++ */ Code:
/** polyadd.c++ */ Thanks |
See this thread. In short you need to have the definition and declaration of your template functions in the same file
|
so it's a g++ bug :(
|
Quote:
|
Wow... that's hard to believe, since my copy of Strousstrup is 9 years old and mentions exactly that in chapter 13. Does Intel's C++ compiler handle templates correctly?
|
According to the Wikipedia article on C++ only two compilers have ever supported the export keyword, Comeau C++ (never heard of that one myself) and a version of Borland C++ Builder. This InformIT article (although marked as "outdated") notes that in practice the export feature actually doesn't do what it sounds like, because the real meat of the template is in the implementation, not the prototype. Taken all together, it sounds like this feature was simply too much for existing compiler technology to cope with.
|
All times are GMT -5. The time now is 04:52 PM. |