POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
30 Jul 2024 00:22:49 EDT (-0400)
  Re: Days 5-  
From: Warp
Date: 20 Apr 2012 08:01:35
Message: <4f91501f@news.povray.org>
Le_Forgeron <lef### [at] freefr> wrote:
> If they are in separate compilation units (different top level *.cpp
> files), each units will get its own version.

  No, they will be merged by the linker (although I'm not completely sure
now if the standard requires it; at the very least it requires for all
static variables inside the function to be merged, IIRC).

  If the context of the template instantiation affects its behavior, then
instantiating it under differing contexts is actually undefined behavior.
(In practice what will usually happen is that only one of them will end up
in the final binary and all the code will call that one; the other contexts
will have no effect on it.)

> (that's the issue with template: generated code can grow very fast if
> you use the template in many *.cpp files)

  Object files might grow, but not the final binary.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.