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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:44:42+00:00 2026-06-09T13:44:42+00:00

I’m trying to get some code originally built with GCC to compile with MSVC,

  • 0

I’m trying to get some code originally built with GCC to compile with MSVC, and am running into a problem with a callback wrapper class in the code. I’ve extracted the critical part of the code below:

template <typename T_func>
struct internal_parameter_resolver;

template <typename R>
struct internal_parameter_resolver<R()> {
    typedef R(*type)();
};

template <typename R, typename P1>
struct internal_parameter_resolver<R(P1)> {
    typedef R(*type)(P1);
};

template <typename T_func, typename internal_parameter_resolver<T_func>::type func>
void bind() {
    // Create and return instance of class Callback...
}

double func1() { return 0.5; }
int func2(double i) { return 0; }

int main() {
    bind<double(), &func1>();    // (Line 23)
    bind<int(double), &func2>(); // (Line 24)

    return 0;
}

While this compiles fine under GCC, MSVC 2010 gives the following error message:

1>c:\users\public\documents\projects\_test\_test\main.cpp(23): error C2975: 'func' : invalid template argument for 'bind', expected compile-time constant expression
1>          c:\users\public\documents\projects\_test\_test\main.cpp(14) : see declaration of 'func'
1>c:\users\public\documents\projects\_test\_test\main.cpp(24): error C2975: 'func' : invalid template argument for 'bind', expected compile-time constant expression
1>          c:\users\public\documents\projects\_test\_test\main.cpp(14) : see declaration of 'func'

Does anybody have an idea why MSVC thinks that those function pointers are not compile-time constants? Or is the problem elsewhere in the code (i.e., not lines 23 and 24)? If it’s a bug in the compiler, I would welcome any suggestions as to a possible workaround.

Thanks!

  • 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-09T13:44:43+00:00Added an answer on June 9, 2026 at 1:44 pm
    template <typename T_func, T_func* >
    void bind() {
        // Create and return instance of class Callback...
    }
    

    Visual C++ is ungood at resolving indirect type definitions, but it’s happy with more concrete types, like above.

    The above shows what to do about the direct problem you have, with Visual C++.

    However, a slightly better design would be to use automatic template argument deduction:

    template <typename T_func >
    void bind( T_func const func ) {
        // Create and return instance of class Callback...
    }
    
    double func1() { return 0.5; }
    int func2(double i) { return 0; }
    
    int main() {
        bind( func1 );      // (Line 23)
        bind( func2 );      // (Line 24)
    }
    

    You can obtain the function result type from std::function, if you want that, and so on.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.