Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the export keyword about? Why do I get a link error when compiling my templates?

0
Posted

Whats the export keyword about? Why do I get a link error when compiling my templates?

0

Although Standard C++ has no such requirement, some compilers require that all function templates need to be made available in every translation unit that it is used in. In effect, for those compilers, the bodies of template functions must be made available in a header file. To repeat: that means those compilers won’t allow them to be defined in non-header files such as .cpp files. To clarify, in C++ese this means that this: // ORIGINAL version of xyz.h template struct xyz { xyz(); ~xyz(); }; would NOT be satisfied with these definitions of the ctor and dtors: // ORIGINAL version of xyz.cpp #include “xyz.h” template xyz::xyz() {} template xyz::~xyz() {} because using it: // main.cpp #include “xyz.h” int main() { xyz xyzint; return 0; } will produce an error. For instance, with Comeau C++ you’d get: C:\export>como xyz.cpp main.cpp C++’ing xyz.cpp… Comeau C/C++ 4.3.4.1 (May 29 2004 23:08:11) for MS_WINDOWS_x86 Copyright 1988-2004 Comeau

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.