Note that there are some explanatory texts on larger screens.

plurals
  1. POOverloaded function ambiguity
    primarykey
    data
    text
    <p>Firstly I should point out that this is my first stackoverflow question, so please bear with me.</p> <p>I'm having some problems overloading a function in c++. I'm trying to create a function with the following prototypes:</p> <pre><code>void push_at_command(std::string, std::vector&lt;std::string&gt;, int); void push_at_command(std::string, std::vector&lt;std::string&gt;, std::vector&lt;std::string&gt;, int); void push_at_command(std::string, std::vector&lt;std::string&gt;, std::vector&lt;std::string&gt;, std::vector&lt;std::string&gt;, int); void push_at_command(std::string, std::vector&lt;std::string&gt;, bool, int); </code></pre> <p>I originally wanted the last overload (the one with the boolean) to accept a boost::regex instead of a string vector;</p> <pre><code>void push_at_command(std::string, boost::regex, int); </code></pre> <p>but ran into ambiguity errors... so just to quickly get the code 'working' I thought I'd add a prototype to accept a flag, and use the first element in the vector to store a regex string, but I seem to be running into similar problems having the boolean.</p> <p>This is how I'm trying to call these various overloads:</p> <pre><code>push_at_command( "AT?S", boost::assign::list_of("(\\d{3}.\\d{3})"), true, 0); push_at_command( "AT?S", boost::assign::list_of("L11")("L12"), 0); push_at_command( "AT?S", boost::assign::list_of("L11"), boost::assign::list_of("L21")("L22"), 0); </code></pre> <p>And this is the error I'm getting:</p> <pre><code>error: call of overloaded ‘push_at_command(const char [5], boost::assign_detail::generic_list&lt;char [4]&gt;, boost::assign_detail::generic_list&lt;char [4]&gt;, int)’ is ambiguous note: candidates are: note: void push_at_command(std::string, std::vector&lt;std::basic_string&lt;char&gt; &gt;, std::vector&lt;std::basic_string&lt;char&gt; &gt;, int) note: void push_at_command(std::string, std::vector&lt;std::basic_string&lt;char&gt; &gt;, bool, int) </code></pre> <p>... which relates to the third function call.</p> <p>Just to note, I had no problems before I added the overload with the bool (or changing the string vector to regex).</p> <p>I am assuming the problem has something to do with me using boost::assign in the function call, and I realise that I don't need to, but I really need 'single line' function calls. ... Any advice welcome, as I am fairly new to C++.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload