Operator overloading based on passed int?
<p>I am trying to implement my own programing language in C++.</p>

<p>When an error occours in my language (for example, during lexical analysis), an exception is thrown to be catched by the main function which then prints its message.</p>

<p>The exception can be of different types: either <code>SyntaxError</code>, or <code>FunctionError</code> and so on, all based on the <code>Error</code> class so that they can all be catched even being of different types.</p>

<p>Each sub class of errors anyway can generate different types of error, each one requiring different informations on what was happening when the error was thrown to construct its error message.</p>

<p>To solve this problem, I accounted for this solution:</p>

<pre><code>//Error contains a public "message" attribute of type std::string, and a constructor to initialize that string

class SyntaxError: public Error {
    SyntaxError(int code, void* infos[]) {
        Error("SintaxError: ");
        switch (code) {
            //each sub error has its own code and based on that the function assumes the pointers to the objects needed to construct the error message are stored in the infos array
            case 1: //Unfinished string
            //it assumes the line at which the error is thrown is stored in the first position of the passed array
                message += "Unfinished string (at line " + std::to_string(*((int*) infos[0])) + ").";
            case 2: //Malformed number
                ...
            ... //other errors, each one assuming in the infos array are stored pointers to different types of objects
        }
    }
};
</code></pre>

<p>This however requires a great setup when you want to throw the error (because you must estabilish what type of error you want to throw and based on that create an array of pointers to the informations required) and it's also pretty messy in the constructor itself: I can't even name the objects required because I can't declare them in the switch statement and I should declare all of them at the start of the function.</p>

<p>So I tought to another solution: overloading the constructor with the objects needed, so that when I want to throw a <em>unfinished string</em> error I just have to pass an <code>int</code>, the line, and when I want to throw a <em>malformed number</em> error I have to pass an <code>int</code> <strong>and</strong> a <code>string</code> (the malformed number), and so on.</p>

<p>The point is, there will be errors requiring the same number, and types, of informations, like, a <em>invalid escape sequence used in string</em> error, for an example, would require an <code>int</code> (the line), and a <code>string</code> (the escape sequence used), just like the <em>malformed number</em> overload, and I don't know how to differentiate them.</p>

<p>So, is there a way to tell the compiler which function between different functions with the same parameter list to call based on an integer I pass to the function?</p>