RE: [Dev-C++] Is it possible - templates (.h and .cpp) ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-04-30 16:29:01
|
export is noramlly used to inform that code or data is available in another object file. With templates, there are no code unless the compiler can se both the template implementation, and some references that uses the template. First then will the compiler instance a copy of the template functions, specifically adjusted according to what template parameters that was supplied. This makes it impossible to use templates without letting the compiler see the full declarations for the template. /Per W On Fri, 30 Apr 2004, manish Shrivastava wrote: > Well, I guess there is a keyword export(as given in Stroustrup's book) wh= ose > purpose is exactly this(separate compilation strategy)..Though as far as = I > know this is not supported by .NET and CodeWarrior. > > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf Of Jorge > Mazzonelli > Sent: Friday, April 30, 2004 7:53 PM > To: dev...@li... > Subject: Re: [Dev-C++] Is it possible - templates (.h and .cpp) ? > > Hi, > excuse me but I'm just a newbie in C++ (most of my developpements are > made in ANSI-C) but was curious about the subject and made some google > search and found this URL: > http://www.cplusplus.com/doc/tutorial/tut5-1.html. There, the author says= at > the end the following: > > /The macro-like functionality of templates, forces a restriction for > multi-file projects: the implementation (definition) of a template class = or > function _must_ be in the same file as the declaration. That means we can= not > separate the interface in a separate header file and we must include both > interface and implementation in any file that uses the templates. / > > /Going back to the library of functions, if we wanted to make a library o= f > function templates, instead of creating a header file (*.h*) we should > create a "template file" with both the interface and implementation of th= e > function templates (there is no convention on the extension for this type= of > file other than there be no extension at all or to keep the .h). The > inclusion more than once of the same template file with both declarations > and definitions in a project doesn't generate linkage errors, since they = are > compiled on demand and compilers that allow templates should be prepared = to > not generate duplicate code in these cases. / > > > > > Hope this helped. > > Jorge > > > Ricardo Amores Hern=E1ndez wrote: > > > She=B4s not talking about Dev-C++ templates, but *C++ Language* > > Templates. ;) More specifically she asked if gcc separate compilation > > of templates. > > By the way, i=B4m in |