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 62627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:30:20+00:00 2026-05-10T18:30:20+00:00

I have the following problem using template instantiation [*]. file foo.h class Foo {

  • 0

I have the following problem using template instantiation [*].

file foo.h

class Foo { public:     template <typename F>     void func(F f)  private:     int member_; }; 

file foo.cc

template <typename F> Foo::func(F f) {      f(member_); } 

file caller.cc

Foo::func(boost::bind(&Bar::bar_func, bar_instance, _1)); 

While this compiles fine, the linker complains about an undefined symbol:

void Foo::func<boost::_bi::bind_t...>

How can I instantiate the function Foo::func? Since it takes a function as argument, I am little bit confused. I tried to add an instantiation function in foo.cc, as I am used to with regular non-function types:

instantiate() {     template<> void Foo::func<boost::function<void(int)> >(boost::function<void(int)>); } 

Obviously, this does not work. I would appreciate if someone can point me in the right direction.

Thanks!

[*] Yes, I read the parashift FAQ lite.

  • 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. 2026-05-10T18:30:20+00:00Added an answer on May 10, 2026 at 6:30 pm

    The answer to this is compiler dependent. Some versions of the Sun C++ compiler would handle this automatically by building a cache of template function implementations that would be shared across separate translation units.

    If you’re using Visual C++, and any other compiler that can’t do this, you may as well put the function definition in the header.

    Don’t worry about duplicate definitions if the header is included by multiple .cc files. The compiler marks template-generated methods with a special attribute so the linker knows to throw away duplicates instead of complaining. This is one reason why C++ has the ‘one definition rule’.

    Edit: The above comments apply in the general case where your template must be capable of linking given any type parameters. If you know a closed set of types that clients will use, you can ensure they are available by using explicit instantiation in the template’s implementation file, which will cause the compiler to generate definitions for other files to link against. But in the general case where your template needs to work with types possibly only known to the client, then there is little point in separating the template into a header file and and implementation file; any client needs to include both parts anyway. If you want to isolate clients from complex dependencies, hide those dependencies behind non-templated functions and then call into them from the template code.

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

Sidebar

Ask A Question

Stats

  • Questions 203k
  • Answers 203k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $this->load->helper('helpername') May 12, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer There is c# library to help you to do this… May 12, 2026 at 8:34 pm
  • Editorial Team
    Editorial Team added an answer With Javascript and CSS, you can make almost everything click-able.… May 12, 2026 at 8:34 pm

Related Questions

I have the following code (sorry for the large code chunk, but I could
I need to manipulate data in fixed array involving mid insertion. Rather than using
I have the following xsl template that I'm using to group my xsl. The
I have the following use case: There's a class called Template and with that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.