Article View: comp.os.os2.programmer.misc
Article #298Re: (Q) Templates: separate compilation with emx/gcc and OS/2
From: Lei ZHOU
Date: Fri, 18 Mar 1994 09:47
Date: Fri, 18 Mar 1994 09:47
37 lines
2776 bytes
2776 bytes
In article <COATES.94Mar18001802@kelvin.physics.uq.oz.au>, coates@kelvin.physics.uq.oz.au (Tony Coates) writes: |> I am trying to get some template code working under g++ (emx 0.8g) |> under OS/2 2.1. The templates work if I have the templates and code |> in one big file which is all compiled at once. However, I wondered |> what approach I should take when linking multiple object files |> together. I expect that for each separate file, I could #include all |> the template code, including the method implementations, but this |> would mean having the same code repeated from module to module. |> However, it also appears that the linker doesn't compile the code on |> demand either if I try just compiling a template source file and |> linking that in. |> If anyone could explain to me the semantics of how template |> specifications are converted into code with g++, and how one |> includes/links this template code to the rest of the project, I would |> be really grateful. I'm afraid I haven't found any texts/examples to |> guide me, though maybe I wasn't looking in the right place. |> Thanks in advance for any help that anyone can give to me, |> Cheers, |> Tony. Please have a look at Lipmann's book "C++ Primer 2nd" Page 197-198. The definition of a template serves only as a prescription for the definition of an infinite set of instances, In itself, a template does not define anything. When the compiler sees the template definition, it stores an internal representation of it, but does not otherwise cause anything to happen. Later, when the compiler sees an actual use of the template, it then instantiates an instance. Solution for small application is to create just one file in which all the instantiations are generated. This file along includes the template text files. All other program files include the template header file. Hope it helps! - Lei
Technical Details
Message-ID:
<1994Mar18.094731.18956@ensmp.fr>Path:
arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!math.ohio-state.edu!jussieu.fr!fontainebleau.ensmp.fr!avon!zhouReferences:
<COATES.94Mar18001802@kelvin.physics.uq.oz.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,fc0e323eac88ae3b X-Google-Attributes: gid109fba,public X-Google-Thread: 10ba33,fc0e323eac88ae3b X-Google-Attributes: gid10ba33,public X-Google-Thread: 11307a,fc0e323eac88ae3b X-Google-Attributes: gid11307a,public X-Google-ArrivalTime: 1994-03-18 01:47:31 PST Newsgroups: comp.os.os2.programmer.misc,comp.lang.c++,gnu.g++.help Path: arc1-ca.pugleaf.net!gmd.de!xlink.net!howland.reston.ans.net!math.ohio-state.edu!jussieu.fr!fontainebleau.ensmp.fr!avon!zhou From: zhou@cri.ensmp.fr (Lei ZHOU) Subject: Re: (Q) Templates: separate compilation with emx/gcc and OS/2 Message-ID: <1994Mar18.094731.18956@ensmp.fr> Sender: zhou@avon (Lei ZHOU) Organization: Ecole des Mines de Paris References: <COATES.94Mar18001802@kelvin.physics.uq.oz.au> Date: Fri, 18 Mar 94 09:47:31 GMT Lines: 37