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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:18:53+00:00 2026-05-20T01:18:53+00:00

Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(

  • 0

Consider following example.

#include <iostream>
#include <boost/optional.hpp>

template < typename A >
int boo( const boost::optional< A > &a );

template < typename A >
int foo( const A &a )
{
    return boo( a );
}

template < typename A >
int boo( const boost::optional< A > & )
{
    return 3;
}


int main()
{
    std::cout << "foo = " << foo( 3 ) << std::endl;
    std::cout << "boo = " << boo( 3 ) << std::endl;
}

Compiling this using g++ 4.3.0 throws the next compiling errors:

dfg.cpp: In function ‘int main()’:
dfg.cpp:25: error: no matching function for call to ‘boo(int)’
dfg.cpp: In function ‘int foo(const A&) [with A = int]’:
dfg.cpp:24:   instantiated from here
dfg.cpp:12: error: no matching function for call to ‘boo(const int&)’

What should I do differently (if possible with references from the C++ standard)?
Why is it happening and how do I fix it?

EDIT

The fix is to create the correct type in foo:

template < typename A >
int foo( const A &a )
{
    const boost::optional< A > optA( a );
    return boo( optA );
}

But the questions still stands: why is it not created automatically?

  • 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-20T01:18:54+00:00Added an answer on May 20, 2026 at 1:18 am
    return boo( a );
    

    Here type of a is int, and there is no function with name boo which accepts argument of type int. Hence you see this error:

    dfg.cpp:25: error: no matching
    function for call to ‘boo(int)’

    Even if int can be implicitly converted into boost::optional<int>, the compiler cannot deduce the template argument for boost::optional<T> from the calling site. It’s one of the non-deduced contexts where you explicitly need to mention the type as,

       return boo<A>(a);
    

    The Standard says in $14.8.2.1,

    if a template-parameter is not used in
    any of the function parameters of a
    function template, or is used only in
    a non-deduced context, its
    corresponding template-argument cannot
    be deduced from a function call and
    the template-argument must be
    explicitly specified
    .

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

Sidebar

Related Questions

Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Let us consider the following factorial example : #include <iostream.h> int factorial(int); void main(void)
Consider the following example: #include <iostream> #include <sstream> #include <vector> #include <wchar.h> #include <stdlib.h>
Consider the following minimal example: #include <iostream> using namespace std; class myostream : public
Consider the following code: #include <iostream> using namespace std; int main() { int x,
Consider the following trivial program adopted from the boost program options examples #include <boost/program_options.hpp>
Consider the following wrapper around Win32's Runtime Dynamic Linking mechanism: #include <boost/noncopyable.hpp> #include <windows.h>
Consider the following code: #include <cstdlib> #include <iostream> #include <string> #include <vector> #include <algorithm>
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)

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.