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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:25:12+00:00 2026-06-18T05:25:12+00:00

Here I have series of overloaded functions that have as input either vector or

  • 0

Here I have series of overloaded functions that have as input either vector or initializer_list. And I want to handle the special case when client code inputs empty initializer_list. The problem is that compiler cannot determine what data was supposed in such empty list. So my question is how I address in function declaration such case.

#include <string>
#include <vector>

using namespace std;
void func(vector<string> v) { }
void func(vector<wstring> v) { }
void func(initializer_list<string> iv) {}
void func(initializer_list<wstring> iv) {}

int main() {
  using namespace std;
  func({"apple", "banana"});
  func({L"蘋果", L"香蕉"});
  func({}); // special case
}

error message:

<stdin>: In function 'int main()':
<stdin>:14:10: error: call of overloaded 'func(<brace-enclosed initializer list>)' is ambiguous
<stdin>:14:10: note: candidates are:
<stdin>:5:6: note: void func(std::vector<std::basic_string<char> >)
<stdin>:6:6: note: void func(std::vector<std::basic_string<wchar_t> >)
<stdin>:7:6: note: void func(std::initializer_list<std::basic_string<char> >)
<stdin>:8:6: note: void func(std::initializer_list<std::basic_string<wchar_t> >)

void func(initializer_list<void> iv) {} – has no effect. I don’t know how to properly declare it.

  • 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-18T05:25:13+00:00Added an answer on June 18, 2026 at 5:25 am

    There’s no way to distinguish this with the parameter alone. You can make one of them a template though, which will then be more costly and less preferable for overload resolution

    void func(vector<string> v) { }
    void func(vector<wstring> v) { }
    template<typename = void>
    void func(initializer_list<string> iv) {}
    void func(initializer_list<wstring> iv) {}
    

    Now calling func({}) will prefer the last function over the function template. Note that func({"hello", "world"}) still prefers the function template over the non-template vector-taking function, because the parameter conversion cost is more important than whether or not a candidate was synthesized from a template.

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

Sidebar

Related Questions

I have a series of functions that are all designed to do the same
I have a series of data that I want to put inside an array
So here is the scenario: i have a series of different repository classes that
I have a series of p tags that I want to have toggle in
I have a series of images that I want to make use of in
I have a series of raphael animations that I want to fire in a
need a quick help here. I have a series of hyperlinks all with the
Here I have piece of code, showing example of how I want to update
I have a series of eight LEDs that I'm trying to fade in and
I have a series of crystal reports that needs to be generated based on

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.