c++.beta - Template member definitions & translation units
- Richard (23/23) Jan 23 2003 2.1 and 2.1-8
- Walter (9/32) Jan 23 2003 Unfortunately, you'll need to put the template bodies into the header fi...
- Richard Grant (6/10) Jan 24 2003 Ok, that's fine for me, and a non exhaustive search of boost lib code in...
- Walter (8/17) Jan 24 2003 files.
- Richard Grant (14/16) Feb 28 2003 In some other thread on Template definitions in different translation un...
- Walter (5/21) Feb 28 2003 Exported templates do not work yet.
- %u Souveek Kumar Bose (15/15) Feb 20 2007 For template function declarations and definitions to be in
2.1 and 2.1-8 Problem: template declaration in one source file (.h), template member function definitions in another source file (unit A), and template member function use in a third source file (unit B). Linker complains that symbol for template member function is undefined. // test.h template <class T> struct A { void fn(); }; // test.cpp #include "test.h" template <class T> void A<T>::fn() { } // main.cpp #include "test.h" void main() { A<int> a; a.fn(); } // Error 42: Symbol Undefined // ?fn ?$A H QAEXXZ (void syscall A<int >::fn(void )) This has slowly become a high priority for me. Richard
Jan 23 2003
Unfortunately, you'll need to put the template bodies into the header files. That's the way it is with a separate compilation model. The good part is that there's no penalty for doing so (other than a bit slower compilation speed). "Richard" <Richard_member pathlink.com> wrote in message news:b0pm9c$3p1$1 digitaldaemon.com...2.1 and 2.1-8 Problem: template declaration in one source file (.h), template memberfunctiondefinitions in another source file (unit A), and template member functionuse ina third source file (unit B). Linker complains that symbol for templatememberfunction is undefined. // test.h template <class T> struct A { void fn(); }; // test.cpp #include "test.h" template <class T> void A<T>::fn() { } // main.cpp #include "test.h" void main() { A<int> a; a.fn(); } // Error 42: Symbol Undefined // ?fn ?$A H QAEXXZ (void syscall A<int >::fn(void )) This has slowly become a high priority for me. Richard
Jan 23 2003
In article <b0ptcq$8f3$1 digitaldaemon.com>, Walter says...Unfortunately, you'll need to put the template bodies into the header files. That's the way it is with a separate compilation model. The good part is that there's no penalty for doing so (other than a bit slower compilation speed).Ok, that's fine for me, and a non exhaustive search of boost lib code indicates awareness of compilation models, but it does create problems with libs that are unaware.. just to be clear: are you saying that this behavior is by design, and that no change is anticipated? Richard
Jan 24 2003
"Richard Grant" <fractal clark.net> wrote in message news:b0r5gj$t14$1 digitaldaemon.com...In article <b0ptcq$8f3$1 digitaldaemon.com>, Walter says...files.Unfortunately, you'll need to put the template bodies into the headerindicatesThat's the way it is with a separate compilation model. The good part is that there's no penalty for doing so (other than a bit slower compilation speed).Ok, that's fine for me, and a non exhaustive search of boost lib codeawareness of compilation models, but it does create problems with libsthat areunaware.. just to be clear: are you saying that this behavior is bydesign, andthat no change is anticipated?Yes. I also don't think you'll find any code otherwise. I think all the existing compilers work that way.
Jan 24 2003
In article <b0rq1h$17o7$1 digitaldaemon.com>, Walter says...Yes. I also don't think you'll find any code otherwise. I think all the existing compilers work that way.In some other thread on Template definitions in different translation units, we were talking about irrelevant details. According to 14-7 of the template introduction, The export keyword handles this issue. But this does not work: export template <class T> struct A { // Error: missing decl-specifier-seq for declaration of 'export' void fn(); }; template <class T> void A<T>::fn() { } int main() { A<int> a; a.fn(); } Richard
Feb 28 2003
Exported templates do not work yet. "Richard Grant" <fractal clark.net> wrote in message news:b3ngi1$2jmr$1 digitaldaemon.com...In article <b0rq1h$17o7$1 digitaldaemon.com>, Walter says...units, weYes. I also don't think you'll find any code otherwise. I think all the existing compilers work that way.In some other thread on Template definitions in different translationwere talking about irrelevant details. According to 14-7 of the template introduction, The export keyword handles this issue. But this does notwork:export template <class T> struct A { // Error: missing decl-specifier-seq for declaration of 'export' void fn(); }; template <class T> void A<T>::fn() { } int main() { A<int> a; a.fn(); } Richard
Feb 28 2003
For template function declarations and definitions to be in different files, the declarations must be available in the file in which they are defined. That is whats the root of all problems in this case For template class/function definitions to be in one file and their declarations in another, you can use one of 2 methods:- In the file test.h, add #include "test.cpp" after the template struct definition Use the export keyword in test.cpp as follows:- export template<class T> void A<T>::fn() {} However, most compilers dont support the keyword export. So, you can do one of two things... 1> Follow method one above 2> Keep template function/struct/class declarations and definitions in the same file.
Feb 20 2007