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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:50:50+00:00 2026-05-26T10:50:50+00:00

I am trying to bind a template function during signaling. However, when I use

  • 0

I am trying to bind a template function during signaling. However, when I use a placeholder in the slot function, I get a “negative subscript” compiler error. I am using Visual Studio
2008. Thanks.

Code:

class My
{
private:
    boost::signals2::signal<void (int)> sig;

public:
    template < typename F, typename T, typename A1 >
    void proxy( F f, T t, A1 a1 )
    {
        boost::bind( f, t, a1 );    // this gets messaged elsewhere
    }

    int foo( int i )
    {
        return i-1;
    }

    int bar( int i )
    {
        return i+1;
    }

    template < typename F, typename T, typename A1 >
    boost::signals2::connection connect( F f, T t, A1 a1 )
    {
        return sig.connect( boost::bind( &My::proxy< F, T, A1 >, t, f, t, a1 ) );
    }

    void main()
    {
        boost::signals2::connection c1 = connect( &My::foo, this, 11 );     // ok
        boost::signals2::connection c2 = connect( &My::bar, this, _1 );     // negative subscript
    }
};

Error:

boost/bind/arg.hpp(37) : error C2118: negative subscript
boost/bind/bind.hpp(450) : see reference to function template instantiation 'boost::arg<I>::arg<A1>(const T &)' being compiled
with
[
    I=1,
    A1=int,
    T=int
]
boost/bind/bind_template.hpp(32) : see reference to function template instantiation 'void boost::_bi::list4<A1,A2,A3,A4>::operator ()<F,boost::_bi::list1<int &>>(boost::_bi::type<T>,F &,A &,int)' being compiled
with
[
    A1=boost::_bi::value<My *>,
    A2=boost::_bi::value<int (__thiscall My::* )(int)>,
    A3=boost::_bi::value<My *>,
    A4=boost::arg<1>,
    F=boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,
    T=void,
    A=boost::_bi::list1<int &>
]
boost/function/function_template.hpp(153) : see reference to function template instantiation 'void boost::_bi::bind_t<R,F,L>::operator ()<T0>(A1 &)' being compiled
with
[
    R=void,
    F=boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,
    L=boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>,
    T0=int,
    A1=int
]
boost/function/function_template.hpp(147) : while compiling class template member function 'void boost::detail::function::void_function_obj_invoker1<FunctionObj,R,T0>::invoke(boost::detail::function::function_buffer &,T0)'
with
[
    FunctionObj=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>,
    R=void,
    T0=int
]
boost/function/function_template.hpp(913) : see reference to class template instantiation 'boost::detail::function::void_function_obj_invoker1<FunctionObj,R,T0>' being compiled
with
[
    FunctionObj=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>,
    R=void,
    T0=int
]
boost/function/function_template.hpp(722) : see reference to function template instantiation 'void boost::function1<R,T0>::assign_to<Functor>(Functor)' being compiled
with
[
    R=void,
    T0=int,
    Functor=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>
]
boost/function/function_template.hpp(1065) : see reference to function template instantiation 'boost::function1<R,T0>::function1<F>(Functor,int)' being compiled
with
[
    R=void,
    T0=int,
    F=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>
]
boost/function/function_template.hpp(1105) : see reference to function template instantiation 'boost::function<Signature>::function<F>(Functor,int)' being compiled
with
[
    Signature=void (int),
    F=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>
]
boost/signals2/detail/slot_template.hpp(137) : see reference to function template instantiation 'boost::function<Signature> &boost::function<Signature>::operator =<F>(Functor)' being compiled
with
[
    Signature=void (int),
    F=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>,
    Functor=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>
]
boost/signals2/detail/slot_template.hpp(81) : see reference to function template instantiation 'void boost::signals2::slot1<R,T1,SlotFunction>::init_slot_function<F>(const F &)' being compiled
with
[
    R=void,
    T1=int,
    SlotFunction=boost::function<void (int)>,
    F=boost::_bi::bind_t<void,boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>>
]
test.cpp(179) : see reference to function template instantiation 'boost::signals2::slot1<R,T1,SlotFunction>::slot1<boost::_bi::bind_t<R,F,L>>(const boost::_bi::bind_t<R,F,L> &)' being compiled
with
[
    R=void,
    T1=int,
    SlotFunction=boost::function<void (int)>,
    F=boost::_mfi::mf3<void,My,int (__thiscall My::* )(int),My *,boost::arg<1>>,
    L=boost::_bi::list4<boost::_bi::value<My *>,boost::_bi::value<int (__thiscall My::* )(int)>,boost::_bi::value<My *>,boost::arg<1>>
]
test.cpp(196) : see reference to function template instantiation 'boost::signals2::connection My::connect<int(__thiscall My::* )(int),My*,boost::arg<I>>(F,T,A1)' being compiled
with
[
    I=1,
    F=int (__thiscall My::* )(int),
    T=My *,
    A1=boost::arg<1>
]
  • 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-26T10:50:51+00:00Added an answer on May 26, 2026 at 10:50 am

    Possibly typo?
    The member function &My::proxy< F, T, A1 > in the question takes the
    placeholder _1‘s type itself instead of the actual parameter int.
    So in this case, changing &My::proxy< F, T, A1 > to
    &My::proxy< F, T, int > will resolve the error.
    Here is a test on ideone.

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

Sidebar

Related Questions

I am trying to call a function but I get an error stating function
I'm trying to use boost::bind with the std::sort function. I want to bind sort
I am trying to use a lambda to pass in place of a function
I have a C++ class where I'm trying to use std::bind1st to bind a
i currently trying to get my model loader to work and got a error
I was trying to understand c++0x std::bind and std::function usage in event handling /
I have a following ListView item template, in which I am trying to bind
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type
In a continuation from this question . I'm trying to bind a given function
I am trying to use decltype inside a template class as follows: #include <functional>

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.