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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:06:02+00:00 2026-06-17T17:06:02+00:00

Consider the following example: #include <utility> #include <iostream> struct bar { void baz() {

  • 0

Consider the following example:

#include <utility>
#include <iostream>

struct bar
{
    void baz() { std::cout << "bar::baz" << std::endl; }
};

template <typename Signature>
struct function_traits;

template <typename ReturnType, typename Class, typename ...ArgumentTypes>
struct function_traits<ReturnType (Class::*)(ArgumentTypes...)>
{
    typedef ReturnType (Class::*Signature)(ArgumentTypes...);
    typedef ReturnType (*FuncPtr)(void const *ip, ArgumentTypes&& ...);

    template <Signature mf>
    static ReturnType wrapper(void const *p, ArgumentTypes&& ...args)
    {
        Class* instance = const_cast<Class*>(static_cast<Class const *>(p));
        return (instance->*mf)(std::forward<ArgumentTypes>(args)...);
    }
};

template <typename Type>
constexpr auto wrap(Type p) -> typename function_traits<Type>::FuncPtr
{
    return &(function_traits<Type>::template wrapper<p>); // ERROR: Address of overloaded function 'wrapper' does not match required type 'void (const void *)'
}

int main()
{
    auto v = wrap(&bar::baz);
}

I’ve tested it with Xcode 4.5.2 – Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Do I want too much?

  • 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-17T17:06:03+00:00Added an answer on June 17, 2026 at 5:06 pm

    The parameter declaration

    constexpr auto wrap(Type p)
    

    is incompatible with the template-name

    template wrapper<p>
    

    Even in a constexpr function, a parameter cannot be used as a constant expression.

    Usually this error manifests itself as an attempt to adjust the constexpr function’s return type according to the value of the argument, but this is a little subtler since the type expression is part of the value computation, with the value always having the same type.

    The fundamental problem is that the template is being asked to do runtime work. You can decide what PTMF to call it with at runtime.

    constexpr never restricts the arguments that may be passed to a function. (I.e., that a function may only be called with constant arguments.) It only makes the function a candidate for use in contexts where a constant is required.

    • 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 <boost/optional.hpp> template < typename A > int boo(
Consider the following example: #include <iostream> #include <iostream> #include <type_traits> template<typename Type, template<typename> class
Consider the following example: struct Scanner { template <typename T> T get(); }; template
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider the following code: #include <iostream> struct X{ X(){ throw 0; } }; void
Consider the following minimal example: #include <iostream> using namespace std; class myostream : public
Consider following example code: #include <iostream> #include <inttypes.h> using namespace std; int f(uint32_t i)
Please consider the following example: #include <string> #include <vector> using std::string; using std::vector; template
Let us consider the following factorial example : #include <iostream.h> int factorial(int); void main(void)
Consider the following use of template template parameters... #include <iostream> template <typename X> class

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.