Re: A little misunderstanding with templates = a big hassle.


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by Daniel Longest on March 18, 2001 at 23:53:53:

In Reply to: A little misunderstanding with templates = a big hassle. posted by Matt Green on March 17, 2001 at 20:01:36:

Definitions of templates should be in the same module as the class definition at this point, so goes the debate on comp.lang.c++ I am aware of a type of "hack" to avoid this in VC++ but it's effectiveness if you plan to compile on other platforms is probably limited. At this point, no compiler supports the "export" keyword defined in the standard (although Comeau C++ is close to having their compiler ready that does support it and is thought to be closer to the standard then most compilers), that's why the definitions usually have to go in the same module. VC++ also has a bug where if your class has a templated member function (the function itself is templated), the definition of this function must be in the class defintion or it won't compile. (Note, this may have been fixed with service pathces, I've been unable to install any to see).

Daniel

: I started drafting my program today, and began messing around with templates and the Array class. I think I remember noticing in class that the slides had both the declaration and the implementation of classes in the same file and it seemed strange. But I went ahead and split it into the cpp file and the h file, as we've been taught. I kept getting linker errors for every function that was used. I check the syntax of the templated member functions and the class against the notes and Stroustrup's documentation.

: Well 2 hours later I was looking on Deja.com's usenet archives and it seems that you have to consolidate the files, since they perform akin to macros. Hopefully this note will save people some time.




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]