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 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

Related Questions

I'm attempting to write a function in assembly that will detect if a longer
I am curretnly attempting to write a script in python that allows me to
I am attempting to write a method that has an optional EventHandler Paramater. it
I have been attempting to write a VBA Script that can parse out other
I am attempting to write a time management tool with wxPython that is ideally
I am attempting to write integration tests for a Grails service that does, among
I am attempting to write a interpreter that will turn a string like: vector(random(0,
I am attempting to write some Java code that takes an image from a
I'm building an MVC3 app for my dynamic web class, and while attempting to
I am attempting to write a firefox addon that will analyze the displayed page

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.