Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 968161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:26:03+00:00 2026-05-16T02:26:03+00:00

I know that in the original C++0x standard there was a feature called export

  • 0

I know that in the original C++0x standard there was a feature called export.

But I can’t find a description or explanation of this feature. What is it supposed to do? Also: which compiler is supporting it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:26:04+00:00Added an answer on May 16, 2026 at 2:26 am

    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 <typename T>
    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 <typename T>
    xyz<T>::xyz() {}
    
    template <typename T>
    xyz<T>::~xyz() {}
    

    because using it:

    // main.cpp
    #include "xyz.h"
    
    int main()
     {
        xyz<int> 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 Computing.  All rights reserved.
    MODE:non-strict warnings microsoft C++
    
    C++'ing main.cpp...
    Comeau C/C++ 4.3.4.1 (May 29 2004 23:08:11) for MS_WINDOWS_x86
    Copyright 1988-2004 Comeau Computing.  All rights reserved.
    MODE:non-strict warnings microsoft C++
    
    main.obj : error LNK2001: unresolved external symbol xyz<T1>::~xyz<int>() [with T1=int]
    main.obj : error LNK2019: unresolved external symbol xyz<T1>::xyz<int>() [with T1=int] referenced in function _main
    aout.exe : fatal error LNK1120: 2 unresolved externals
    

    because there is no use of the ctor or dtor within xyz.cpp, therefore, there is no instantiations that needs to occur from there. For better or worse, this is how templates work.

    One way around this is to explicitly request the instantiation of xyz, in this example of xyz<int>. In a brute force effort, this could be added to xyz.cpp by adding this line at the end of it:

    template xyz<int>;
    

    which requests that (all of) xyz<int> be instantiated. That’s kind of in the wrong place though, since it means that everytime a new xyz type is brought about that the implementation file xyz.cpp must be modified. A less intrusive way to avoid that file is to create another:

    // xyztir.cpp
    #include "xyz.cpp" // .cpp file!!!, not .h file!!
    
    template xyz<int>;
    

    This is still somewhat painful because it still requires a manual intervention everytime a new xyz is brought forth. In a non-trivial program this could be an unreasonable maintenance demand.

    So instead, another way to approach this is to #include "xyz.cpp" into the end of xyz.h:

    // xyz.h
    
    // ... previous content of xyz.h ...
    
    #include "xyz.cpp"
    

    You could of course literally bring (cut and paste it) the contents of xyz.cpp to the end of xyz.h, hence getting rid of xyz.cpp; it’s a question of file organization and in the end the results of preprocessing will be the same, in that the ctor and dtor bodies will be in the header, and hence brought into any compilation request, since that would be using the respective header. Either way, this has the side-effect that now every template is in your header file. It could slow compilation, and it could result in code bloat. One way to approach the latter is to declare the functions in question, in this case the ctor and dtor, as inline, so this would require you to modify xyz.cpp in the running example.

    As an aside, some compilers also require that some functions be defined inline inside a class, and not outside of one, so the setup above would need to be tweaked further in the case of those compilers. Note that this is a compiler issue, not one of Standard C++, so not all compilers require this. For instance, Comeau C++ does not, nor should it. Check out http://www.comeaucomputing.com/4.0/docs/userman/ati.html for details on our current setup. In short, Comeau C++ supports many models, including one which comes close to what the export keyword’s intentions are (as an extension) as well as even supporting export itself.

    Lastly, note that the C++ export keyword is intended to alleviate the original question. However, currently Comeau C++ is the only compiler which is being publicized to support export. See http://www.comeaucomputing.com/4.0/docs/userman/export.html and http://www.comeaucomputing.com/4.3.0/minor/win95+/43stuff.txt for some details. Hopefully as other compilers reach compliance with Standard C++, this situation will change. In the example above, using export means returning to the original code which produced the linker errors, and making a change: declare the template in xyz.h with the export keyword:

    // xyz.h
    
    export
    // ... ORIGINAL contents of xyz.h ...
    

    The ctor and dtor in xyz.cpp will be exported simply by virtue of #includeing xyz.h, which it already does. So, in this case you don’t need xyztir.cpp, nor the instantiation request at the end of xyz.cpp, and you don’t need the ctor or dtor manually brought into xyz.h. With the command line shown earlier, it’s possible that the compiler will do it all for you automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
I know its probably possible, but is it practical and doable to try and
I know its probably possible, but is it practical and doable to try and
There doesn't seem to be any tried and true set of best practices to
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I would like to remove/delete a migration file. How would I go about doing
I would like to update my SQL lite database with the native update-method of
I'm doing some changes on my routes, and suddenly the following is appearing in
I have a snippet to create a 'Like' button for our news site: <iframe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.