Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction Pointers in C++/CX
    primarykey
    data
    text
    <p><strong>Background</strong></p> <p>I'm writing a Windows Store App in C++ using the Windows Store Unit Test Project. While trying to figure out how to test that an exception was raised, I found Assert::ExpectedException in CppUnitTestAssert.h. Its signatures are below:</p> <pre><code>template&lt;typename _EXPECTEDEXCEPTION, typename _RETURNTYPE&gt; static void ExpectException(_RETURNTYPE (*func)(), const wchar_t* message = NULL, const __LineInfo* pLineInfo = NULL) { ... } </code></pre> <p>and</p> <pre><code>template&lt;typename _EXPECTEDEXCEPTION, typename _FUNCTOR&gt; static void ExpectException(_FUNCTOR functor, const wchar_t* message = NULL, const __LineInfo* pLineInfo = NULL)` { ... } </code></pre> <p><strong>The Question Is:</strong></p> <p>It's been a LONG time since I coded in C++, so I'm having difficulty figuring out how to call the method correctly. I keep getting the following error:</p> <pre><code>'Microsoft::VisualStudio::CppUnitTestFramework::Assert::ExpectException' : none of the 2 overloads could convert all the argument types </code></pre> <p>I realize this may be actually be a misunderstanding of "pure" C++, but I'm not sure if C++/CX may have different rules for using function pointers that C++. Or at least what I remember the rules to be.</p> <p>EDIT: </p> <p>I'm attempting to use the function pointer overload, _RETURNTYPE (*func)(), not the __FUNCTOR overload. Here is the code that is failing to compile. </p> <pre><code>Assert::ExpectException&lt;InvalidArgumentException, int&gt;(&amp;TestClass::TestMethod); </code></pre> <p>Here is TestMethod:</p> <pre><code>void TestMethod() { } </code></pre>
    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