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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:38:13+00:00 2026-06-13T22:38:13+00:00

I don’t know if what I have is a compiler bug or if I

  • 0

I don’t know if what I have is a compiler bug or if I just don’t know the syntax for what I’m trying to do. Imagine a function that takes 2 array references:

void takeArrays(const char (&str1)[4], const char (&str2)[4]) {
}

This compiles fine when called with:

takeArrays("foo", "bar");

Why would I want to do this? Because passing const char* loses the size information of the string literal, and that’s important for what I’m doing.

What I really want to do, however, is pass a variadic number of array references. This is where things get slightly ugly (it gets worse). I naively tried this:

template<typename... Args>
void takeArrays(const char (&Args... strs)[4]) {
}

And got "error: variable or field ‘takeArrays’ declared void" and "error: expected primary-expression before ‘const’" (gcc 4.6). So I tried this:

template<typename... Args>
void takeArrays(const char (&(Args... strs))[4]) {
}

And got "no matching function for call to ‘takeArrays(const char [4], const char [4])’" and "candidate is template<class ... Args> void takeArrays(const char (& (*)(Args ...))[4])". Which is unreadable but seems close to what I want. I’ve tried many variations and can’t seem to get it to compile.

Assuming there’s a proper way to write the above, what I really want to do is call:

takeArrays("foo", "foobar", "longerstring");

And get a variadic list of arrays of different sizes, i.e. the call above should be expanded by the compiler to:

void takeArrays(const char (&str1)[4], const char (&str2)[7],
                const char (&str3)[13]);

Which was the first think I tried doing, and my attempt was something like:

template<size_t... Sizes>
void takeArrays(const char (&strs)[Sizes]...);

Needless to say all I got was error messages. I’m aware that what I’m trying to do is a bit crazy but I really want to know if it’s possible, and if so, what the appropriate syntax is. Thanks in advance.

  • 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-13T22:38:15+00:00Added an answer on June 13, 2026 at 10:38 pm

    The syntax for variadic arrays of the same element type is:

    template<size_t... Sizes>
    void takeArrays(const char (&...args)[Sizes]);
    

    This is similar to the general variadic const reference syntax:

    template<typename... Args>
    void takeArrays(const Args &...args);
    

    An easy way to remember is that the ellipsis goes immediately before the parameter name.

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

Sidebar

Related Questions

Don't know much about running a function on every item in an array, still
don't know if the title describes anything about what I'm trying to say but
Don't know the difference between the System.Window.Controls.TextBox and System.Windows.Forms.TextBox . Noticed that the System.Windows.Forms.TextBox
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know how to explain it better but i'm trying to get a response
Don't know if it's I'm doing it wrong or if there's a bug (I
Don't know if this has been answered before. Have custom routes to users. If
Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't know whether I'm having a "thick day" - but I just wondered what
Don't yell at me! i have seen many threads claiming that HTML cannot be

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.