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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:37:31+00:00 2026-05-13T11:37:31+00:00

I have some trouble forward declaring a function that uses boost::enable_if : the following

  • 0

I have some trouble forward declaring a function that uses boost::enable_if: the following piece of code gives me a compiler error:

// Declaration
template <typename T>
void foo(T t);

// Definition
template <typename T>
typename boost::enable_if<boost::is_same<T, int> >::type foo(T t)
{
}

int main()
{
    foo(12);
    return 0;
}

When compiling, I get an “ambiguous call to foo” error. According to the definition of enable_if, the ‘type’ typedef corresponds to void when the condition is true, so as far as I can see, the two signatures of foo match. Why does the compiler think they are different, and is there a correct way to forward declare foo (preferably without repeating the enable_if part)?

  • 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-13T11:37:32+00:00Added an answer on May 13, 2026 at 11:37 am

    This is not only a problem with enable_if. You get the same error on Visual Studio and gcc with the following code:

    struct TypeVoid {
      typedef void type;
    };
    
    template<typename T>
    void f();
    
    template<typename T>
    typename T::type f() {
    }
    
    int main()
    {
      f<TypeVoid>();
      return 0;
    }
    

    I think the main problem is that the return type (before instantiation) is part of the signature of a template function. There is more information here.

    Regarding your code, if the declaration refers to the definition, you should match both:

    // Declaration       
    template <typename T>       
    typename boost::enable_if<boost::is_same<T, int> >::type foo(T t);       
    
    // Definition       
    template <typename T>       
    typename boost::enable_if<boost::is_same<T, int> >::type foo(T t)       
    {       
    }
    

    If the declaration refers to a different function, the compiler would never be able to choose the correct one for ints, because they both are valid. However, you can disable the first one for ints using disable_if:

    // Other function declaration
    template <typename T>
    typename boost::disable_if<boost::is_same<T, int> >::type foo(T t);
    
    // Defition
    template <typename T>       
    typename boost::enable_if<boost::is_same<T, int> >::type foo(T t)       
    {       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Operator overloading methods have to live inside the class they… May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer It's a bug in current PDT Release in Helios. May 16, 2026 at 10:28 am
  • Editorial Team
    Editorial Team added an answer new double*[num] is an array of double pointers i.e. each… May 16, 2026 at 10:28 am

Trending Tags

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

Top Members

Related Questions

I have some trouble setting up Tramp with EmacsW32 and cygwin. I have configured
I have a mobile application that I'm using with Facebook connect. I'm having trouble
I have some trouble with regex and php here: <span style=color: blue>word1</span> word by
I have some trouble for choosing the right type of exception to throw when
I have trouble to find the kernel API to enable some qdisc policies tc
I have real trouble understanding mod_rewrite, and got some help in creating a RewriteRule
I am experimenting with the c-language right at the moment, yet i have some
I am using BeautifulSoup in Python and am having trouble replacing some tags. I
I'm having trouble selecting the text inside a span element that resides in another
I have been developing a small project meant to run under weblogic 8.1. Richfaces

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.