Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need to use <code>printf</code> wherever in the code, but you will need to call <code>TestClass::Log</code> with extra parameters <code>__FILE__</code> and <code>__func__</code>.</p> <p>Don't threat however, you can create a macro for that so you don't have to write down the extra parameters on each call:</p> <pre><code>#define TEST_CLASS_LOG(testClassInstance,status) \ testClassInstance.Log((int)status, __FILE__, __func__); </code></pre> <p>and instead of calling</p> <pre><code>tt.Log((int)1); </code></pre> <p>you would call</p> <pre><code>TEST_CLASS_LOG(tt,1); </code></pre> <p>You'd need to change the <code>Log</code> signature to account for the extra parameters of course:</p> <pre><code>void Log(int status, const char* fileName, const char* functionName); </code></pre> <p>Also, I see <code>Log</code> isn't accessing any class members, so you can make it even easier and make it <code>static</code>:</p> <pre><code>class TestClass { static void Log(int status); }; void TestClass::Log(int status, const char* file, const char* func) { printf("%s %s %i", file, func, status); } #define TEST_CLASS_LOG(status) \ TestClass::Log((int)status, __FILE__, __func__); </code></pre> <p>So, if you do it like this, you'd only need to call:</p> <pre><code>TEST_CLASS_LOG(1); </code></pre> <p>Unfortunately there's no way to do this automatically, without modifying your code, as macros expand at runtime. What your compiler sees now is:</p> <pre><code>void TestClass::Log(int status) { printf("%s %s %i","Test.cpp","Log", status); } </code></pre> <p>that is why you need the file name and function name passed as parameters.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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