templates being exported

R

Rahul

Hi Everyone,

I was looking at the link,

http://www.comeaucomputing.com/4.0/docs/userman/export.html

and it looks like the basic purpose of exporting templates is make
sure that they are visible in other compilation units for the compiler
to perform instantiation... is this because template instantiation is
something done at compile time by the compiler?

had template instantiation been done at linking time, would extern
keyword have worked? I understand that it really doesn't make sense
for the linker to do, i'm just trying to understand the reason why
export keyword came into picture...

Thanks in advance!!!
 
J

James Kanze

I was looking at the link,

and it looks like the basic purpose of exporting templates is make
sure that they are visible in other compilation units for the compiler
to perform instantiation...

No. The main purpose of exporting templates is to prevent their
being parsed in the context of the user. The implementation of
an exported template will not be affected by symbols (nor
macros) that the user might introduce. A second purpose is to
reduce the time of recompilations if the template implementation
is modified.
is this because template instantiation is something done at
compile time by the compiler?

When the template instantiation occurs is not specified; I've
used compilers which do it at compile time, and compilers which
do it at link time.
had template instantiation been done at linking time, would
extern keyword have worked? I understand that it really
doesn't make sense for the linker to do, i'm just trying to
understand the reason why export keyword came into picture...

The reason is basically because some people wanted to be able to
use templates in large applications; they didn't want the
template implementation to be subject to the aleas of whatever
else a user might have defined in the file using it. Basically,
they wanted templates to "work", just like any other class or
function "works".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top