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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:05:18+00:00 2026-05-26T19:05:18+00:00

Ok, I’m using Visual Studio 2010 to mess with lambdas in templates. VC++ has

  • 0

Ok, I’m using Visual Studio 2010 to mess with lambdas in templates. VC++ has an odd quirk dealing with template parameters, but I found a workaround for calling a static function of a template parameter (T::magic in this example) by using the auto keyword. However, I have hit another hitch.

Say I have one of many classes with a function “magic”, and only the first 2 parameters matter for my call later. It may or may not have some defaulted parameters after the first 2. I don’t really care about them for this application, I only need to call magic(start, otherthing). Uhoh is one of these classes:

struct Uhoh
{
 static int magic(char* start, int otherthing, bool doom = false);
}

I do the call with this template. I have to use a workaround of using the auto type to get T::magic for it to work in the lambda function.

template<typename T> void example()
{
 auto themagic = T::magic;

 std::function<int (char*)> test = [=](char* start) -> int
 {
  return themagic(start, 0);
 };

 test(0);
}

And then I call it or whatever.

int main()
{
 example<Uhoh>();
}

I get an error about “too few arguments for call”, even though “magic” can take two arguments. Now, I can’t know for sure what the type will be for “otherthing” in any of the various “magic” functions. All I know is that 0 will be a valid value. Passing the type of whatever otherthing will be to the function “example” will be an extreme annoyance at best.

How can I properly type “themagic” so that VC++ doesn’t throw an error?

  • 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-26T19:05:18+00:00Added an answer on May 26, 2026 at 7:05 pm
    auto themagic = T::magic;
    

    Here the information that the third parameter of T::magic has default value is lost, as the type of themagic is deduced as int (*)(char*, int, bool), which cannot have any default value for the third parameter. So you cannot call themagic with only two arguments. You’ve to pass third argument as well.

    So do this:

    std::function<int (char*)> test = [=](char* start) -> int
    {
      return themagic(start, 0, false);
    };
    

    Please note that default-value for a function parameter is not a part of the function signature, which means when you write

    auto themagic = T::magic;
    

    then type of themagic cannot be deduced as int (*)(char*, int, bool=false).

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.