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

  • SEARCH
  • Home
  • 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 8968919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:31:16+00:00 2026-06-15T17:31:16+00:00

I want to export template functions from DLL. I know I can use template

  • 0

I want to export template functions from DLL. I know I can use template specialization method as following.
func.hpp
/*declare*/
template<typename T>
DLL_EXPORTS T func(T para);


/*specialization*/
template<>
DLL_EXPORTS int func<int>(int para);

func.cpp
template<>
DLL_EXPORTS int func<int>(int para)
{return para;}

If I use template specialization. I should rewrite the func code for every type. It’s not a good solution. But this is the only way I can found from the C++ Primer.
I found another way occasionally from someone else’s codes, as following.

func.hpp
/*declare*/
template<typename T>
DLL_EXPORTS T func(T para);

func.cpp
template<typename T>
DLL_EXPORTS T func (T para)
{return para;}


/*Instantiation*/
template
DLL_EXPORTS int func<int>(int);

He use template DLL_EXPORTS int func<int>(int) to instantiate the template. you can’t add <> after the keyword template. This way also works on class template.

My question: I can’t find the way in the book. So I’m afraid that it’ll not work sometimes. Is it supported by the C++ standard?

  • 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-06-15T17:31:17+00:00Added an answer on June 15, 2026 at 5:31 pm

    Yes, it called explicit instantiation See 14.7.2 of the C++11 standard (sorry I have no C++03 nearby).

    You may instantiate in your translation unit as much as you wish instances of your template w/ any types you want, and this code will be placed into your DLL. And everything else just wouldn’t.

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

Sidebar

Related Questions

I want to export objects to XML and create XSD. following are the base
I've the following problem: I've created a DLL in C++ with a template class
I want to export data from mysql tables to excel sheet. I am using
I want to export data from one table into a new one with a
I want to export signed apk file from my Android Project with a terminal
I have a pretty simple directive that I want to load the template from
I want to export some classes, say, Dog and Cat . One way to
I want to export TVP (Type of DataTable) to .csv file, or .xls, but
I want to export my simple application in xcode 4.33 But I failed to
I want to export the assemblies built in my project. But where are they

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.