Helmut Zeisel wrote:
On Apr 24, 3:40 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Sure. The point here is, you need to provide the definition of
the function, and where it comes from is unknown *at the time of
compiling a call to it*.
Yes
>What you can do is provide another
module with the definition of the function *template* and, along
with that, an _explicit_ instantiation for myF<int>.
Do *I* have to provide is or is it enough when someone else does this
and just
provides a compiled version without giving access to the source of
myF<T?
Are you trying to be cute here? You're the one _linking_ the damn
program, aren't you? So, _you_ are going to *provide the definition*
to your linker. In what form is up to you and your linker. If you
can only get it in the form of an object file, and your linker likes
that, power to you!
>
>... and puts
an instruction for the linker to look for it in all other places
where the linker usually looks for stuff. The linker does, but
cannot find the definition of myF<int>.
Same question again: does the linker need the definition/source of
myF<Tor is it enough if it finds a compiled version of myF<int?
It's up to your linker, isn't it? The Standard says nothing about
the linking except that it can be a separate step.
>
>Now, technically speaking, the code you presented here is NOT
a complete C++ program because it does not contain a *definition*
of myF<int(or anything from which such definition can be made).
In that sense, *linking* is an integral part of what the Standard
calls "compilation".
As I understand this means that I have to provide the definition/
source of myF<T>.
Whatever floats your boat. The Standard requires the _definition_
to *exist*. And since the Standard only talks of the source form,
then yes, the source form *has to exists somewhere*. Do you have
to give it to the compiler/linker every time you build your 'main'
program in the *source form*? Usually no. But that process (what
we know as "separate compilation") is not standardized. It is
totally up to the implementation to _allow_ that.
VC++ 2005 was able to link when just the a compiled version of
myF<intwas available.
Good.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask