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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:23:30+00:00 2026-05-11T05:23:30+00:00

I am attempting to write a dynamic dispatcher for a function that’s templated on

  • 0

I am attempting to write a dynamic dispatcher for a function that’s templated on integer values (not on types). While I could either write a code generator or use a big macro chain to create the dispatcher source, it seems that a templated solution would be more elegant.

I’ve stripped down my dispatcher to a simple form (which doesn’t actually do any dispatching):

// works fine with full template specialization template <int N> struct TestDispatcher1D {   int f(int n) {     if (n == N) return n; // replace me with actual dispatch     TestDispatcher1D<N-1> t;     return t.f(n);   } };  template<> struct TestDispatcher1D<-1> {   int f(int n) { return -1; } };  // partial template specialization is problematic template <int M, int N> struct TestDispatcher2D {   int f(int m, int n); };  template<int M> struct TestDispatcher2D<M,-1> {   int f(int m, int n) { return -1; } };  template<int N> struct TestDispatcher2D<-1,N> {   int f(int m, int n) { return -1; } };  template<> struct TestDispatcher2D<-1,-1> {   int f(int m, int n) { return -1; } };  template <int M, int N> int TestDispatcher2D<M,N>::f(int m, int n) {   if ((n == N) && (m == M)) return n + m; // replace me with actual dispatch   if (m < M) {     if (n < N) {       TestDispatcher2D<M-1,N-1> t;       return t(m,n);     } else {       TestDispatcher2D<M-1,N> t;       return t(m,n);     }   } else {     TestDispatcher2D<M,N-1> t;     return t(m,n);   } }  // test code void testIt() {   {      TestDispatcher1D<16> t;      t.f(16);    }   {     TestDispatcher1D<16>t;      t.f(0);   }   {     TestDispatcher2D<16,16>t;      t.f(8,8);   } } 

When compiling this on gcc 4.1.1, I get the following errors:

 t.cpp: In member function 'int TestDispatcher2D::f(int, int) [with int M = 16, int N = 16]': t.cpp:63:   instantiated from here t.cpp:40: error: no match for call to '(TestDispatcher2D) (int&, int&)' t.cpp:63:   instantiated from here t.cpp:43: error: no match for call to '(TestDispatcher2D) (int&, int&)' t.cpp:63:   instantiated from here t.cpp:47: error: no match for call to '(TestDispatcher2D) (int&, int&)' 

Apparently, when I try to create the recursive objects, the compiler isn’t treating this as a request to instantiate a new template.

Any suggestions?

  • 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. 2026-05-11T05:23:31+00:00Added an answer on May 11, 2026 at 5:23 am

    You’re simply not calling the f() function in your recursive call, you’re trying to ‘call the object’:

    You write:

    TestDispatcher2D<...> t; return t(m,n); 

    But you want:

    TestDispatcher2D<...> t; return t.f(m,n); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 182k
  • Answers 183k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I honestly don't think you'll find one. What you're asking… May 12, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer Extensions are low-level. Usually written in C/C++, and compiled into… May 12, 2026 at 4:33 pm
  • Editorial Team
    Editorial Team added an answer If you can upgrade to Snow Leopard it's included out… May 12, 2026 at 4:32 pm

Related Questions

I am attempting to write a dynamic dispatcher for a function that's templated on
I'm seeing a problem while attempting to run a java servlet under eclipse (Ganymede),
I am attempting to write a one-line Perl script that will toggle a line
I am attempting to write a component in C# to be consumed by classic
I am attempting to write a .NET component. The component will be dropped onto

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.