title: C++ - style passing caller file and line to function (equivalent of __FILE__ and __LINE__)
body: <p>I know, that my question is similar to this:
  <a href="https://stackoverflow.com/questions/4196431/passing-the-caller-file-line-to-a-function-without-using-macro">Passing the caller __FILE__ __LINE__ to a function without using macro</a></p>
  
  <p>But I'm wondering, why there is no c++ equivalent of caller file and line passing to a function.</p>
  
  <p>Having classes, templates, default arguments and more strict const-correctness makes a lot of macro usage obsolete, but when I want to pass caller file and line to a function, I will go in trouble for 2 reasons: 1. Default arguments (hard to replace all kinds of calls with a macro), 2. Macros break class member name scope. (startTimer macro would be global)</p>
  
  <p>Thinking about the default arguments to functions, why are there no default-args-style replacements for <strong>FILE</strong> and <strong>LINE</strong> macros? It could be done like this:</p>
  
  <pre><code>void startTimer(int type, int id=0, string file = _CALLER_::FILE, int line = _CALLER_::LINE)
  </code></pre>
  
  <p>If the compiler, while looking for function calls of startTimer, can replace the id parameter with 0, where it isn't mentioned, it should be possible to replace file and line with the corresponding <em>CALLER</em> members, which in this example depend on the file, being processed, and the line where the call is made - something that the compiler knows while parsing a cpp file.</p>
  
  <p>Knowing the caller of a member function may be useful for debugging - on which file/line has something been called, which leads to a problem later.</p>