CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2003
    Location
    Karachi, Pakistan
    Posts
    38

    Compiling tempate class implementation into a lib file

    If any one wants to distribute it's code containing implementation of template classes and he doen't want anyone to see the code, then obviously he would have to make a library file for that.
    I've been reading solutions for compiling template classes, but all those require text files, such as h and/or .cpp.
    Now, could you tell me how to hide the implementation code of template classes or in other words, a way to produce a library file that can be distributed to others, so they can't see the code.
    There must be a solution, otherwise how c++ compiler vendors made those standard template libraries?

  2. #2
    Join Date
    Jun 2003
    Location
    Gjøvik, Norway
    Posts
    204
    You really can't... As you have already been told in another thread!

    And all of the STL code is right there in the header files.

  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Hamid,

    All of the answers in the other post as well as the response in this post are correct. Normal template programming must be included and visible to the user for instantiation.

    The usual implementations of the STL (Standard Template Library) do, in fact, rely on template programming which can not be hidden from the user.

    There is a mechanism in the C++ standard called export. The export keyword should allow one to embed the templated code within a C++ source file. However, I do not have any experience with the export keyword and support for this language feature is rare.

    Good luck.

    Sincerely, Chris.

    You're gonna go blind staring into that box all day.

  4. #4
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Exported templates only exist as compiler-specific extensions.
    All the buzzt
    CornedBee

  5. #5
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Assmaster
    You really can't... As you have already been told in another thread!

    And all of the STL code is right there in the header files.
    Note that ten days after this was posted, I was told that that is not true. See STL and Linux wherein I said:
    There is not a library for the STL. The STL is (usually) only source code and exists entirely in the headers.
    and the response was:
    That is not true
    I wonder what the truth is.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #6
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    Originally posted by Sam Hobbs
    I wonder what the truth is.
    The standard certainly does not dictate this one way or the other. In fact there does not have to be a file corresponding to <map>. It could be a special symbol handled entirely by the compiler.

    A compiler could require linking with a library to use certain features of STL. I don't think this violates any rule of the standard.

    Jeff

  7. #7
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    I think that for a while the Dinkumware version of the STL provided the implementation of basic_*stream in .cpp file, using the exported templates feature of MSC++. This meant that only the char and wchar_t versions could be used though.
    All the buzzt
    CornedBee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured