{"id":103628,"date":"2020-04-02T07:00:00","date_gmt":"2020-04-02T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=103628"},"modified":"2020-04-02T06:07:41","modified_gmt":"2020-04-02T13:07:41","slug":"20200402-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20200402-00\/?p=103628","title":{"rendered":"Error compiling C++\/WinRT runtime class: function does not take N arguments"},"content":{"rendered":"<p>You&#8217;re coding up a C++\/WinRT runtime class, and the compiler spits out an error message:<\/p>\n<pre style=\"white-space: pre-wrap;\">error C2660: 'MyClass::Thing1': function does not take N arguments\r\n<\/pre>\n<p>If you&#8217;re really unlucky, you&#8217;ll get<\/p>\n<pre style=\"white-space: pre-wrap;\">error C2064: term does not evaluate to a function taking N arguments\r\n<\/pre>\n<p>where <var>N<\/var> is probably 0 or 1.<\/p>\n<p>You may have failed to implement all the necessary overloads of a method.<\/p>\n<p>C++\/WinRT events are represented by a pair of overloads:<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Operation<\/th>\n<th>Signature (simplified)<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>Register<\/td>\n<td><tt>event_token Event(Delegate const&amp; handler);<\/tt><\/td>\n<td><tt>token = o.Event(handler);<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Unregister<\/td>\n<td><tt>void Event(event_token const&amp; token);<\/tt><\/td>\n<td><tt>o.Event(token);<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>C++\/WinRT read\/write properties are also represented by a pair of overloads:<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Operation<\/th>\n<th>Signature (simplified)<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>Read<\/td>\n<td><tt>T Property();<\/tt><\/td>\n<td><tt>auto value = o.Property();<\/tt><\/td>\n<\/tr>\n<tr>\n<td>Write<\/td>\n<td><tt>void Property(T const&amp; value);<\/tt><\/td>\n<td><tt>o.Property(value);<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>And naturally, if you have overloaded methods, then they are represented by, um, overloaded methods.<\/p>\n<table style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Signature (simplified)<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td><tt>void Method();<\/tt><\/td>\n<td><tt>o.Method();<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>void Method(int32_t value);<\/tt><\/td>\n<td><tt>o.Method(2);<\/tt><\/td>\n<\/tr>\n<tr>\n<td><tt>void Method(int32_t value, hstring name);<\/tt><\/td>\n<td><tt>o.Method(2, L\"Bob\");<\/tt><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If you fail to implement all of the required methods, you will get an error when the C++\/WinRT autogenerated code tries to call one of the missing overloads. When there is a mismatch between the call site and the function prototype, the compiler assumes that the prototype is correct and the call site is wrong. Therefore, the error won&#8217;t be &#8220;You forgot to declare the 1-parameter overload of this method.&#8221; It&#8217;ll be &#8220;The method I found doesn&#8217;t take 1 parameter.&#8221;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to cover all the overloads.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-103628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You need to cover all the overloads.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/103628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=103628"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/103628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=103628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=103628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=103628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}