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

The Archive Base Latest Questions

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

its templates again ;-) Given the following template member functions and CRTP class: template<typename

  • 0

its templates again 😉 Given the following template member functions and CRTP class:

template<typename T>
struct base
{
   ...
};

struct derived : public base<derived>
{
   ...
};

struct some_class
{
    template<typename T>
    void match(base<T>* array, size_t count)
    {
        ...
    };

    template<typename T, size_t count>
    void match(base<T> (&array)[count])
    {
        ...
    };
};

Why doesn’t the compiler find a match for the second function:

derived array[10];
some_class foo;

foo.match(array, 10); // works fine
foo.match(array);     // Error: no matching function for call to some_class::match(derived array[10])

I would expect the second template function could deduct the compile-time fixde array size, but apparently the function is not considered. Why?

Thanks

Edit: strangely the following version compiles fine:

    template<typename T, size_t count>
    void match(T (&array)[count])
    {
        ...
    };

So I suspect that at some point the original version gets ruled out for some reason I just don’t see.

  • 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:44:30+00:00Added an answer on May 26, 2026 at 10:44 am

    An array of Derived cannot be converted to an array of Base. If you ever did anything with the array except access the first element in the first constructor, it would be Undefined Behaviour.

    Taking the reference correctly protects you from this situation, as the code doesn’t compile. However, it will compile by decaying the array to a single pointer, which can decay to a pointer to Base, which makes the Base<T>* overload viable, but still bad.

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

Sidebar

Related Questions

Within our company we use a proprietary template engine, which stores its templates in
I'm trying to create a template wrapper class which inherits from its template parameter
C++ templates have been a blessing in my everyday work because of its power.
I have a button control which its template is stilyzed in an external resource
In django templates, it's common to do the following: <img src={{ MEDIA_URL }}/img/someImage.jpg> How
I've found a sample template in the ANTLR website, its the Javatreeparser.g, which the
Is it possible to have a listbox displaying its items with a control template
So here is my dilemma: I have a base class (Let's say a generic
I just implemented (once again) a recursive template for computing the factorial of an
Here is the subsonic asp.net mvc application http://subsonicproject.com/docs/MVC_Starter_Template but its for MVC 1.0. How

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.