Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,794 of 33,346    |
|    Pete Becker to Robi-Wan-Kenobi    |
|    Re: template function's visibility    |
|    14 Jan 12 13:49:01    |
      72501454       From: pete@versatilecoding.com              On 2012-01-14 02:28:12 +0000, Robi-Wan-Kenobi said:              >       > i just discovered something strange: I had two template functions with       > the same name and signature. Both were defined and declared in       > different cpp-files.       >       > […]       >       > What i observed when i was fixing a bug was that the call of myFunc in       > FileB called the template function from FileA!       >              Formally, if the two definitions are different, that's a violation of       the One Definition Rule, and the behavior of the program is undefined.              In practice, what happens is that the linker sees two template function       instantiations with the same mangled name and picks one, on the       assumption that they're the same. That's because a single template       definition, in a header file, that is used in two source files will       create two instantiations, one in each source file. That's okay, but       having two copies of the same template instantiation is, at best,       confusing, so the linker picks one.              --        Pete       Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The       Standard C++ Library Extensions: a Tutorial and Reference       (www.petebecker.com/tr1book)                      [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca