question

flaviu avatar image
0 Votes"
flaviu asked JeanineZhang-MSFT commented

'invoke_result_t': use of dependent type name must be prefixed

I have a code:

 //add any arg # function to queue
 template <typename Func, typename... Args>
 auto Add(Func&& f, Args&&... args)
 {
     //get return type of the function
     using RetType = std::invoke_result_t<Func, Args...>;

and on last line, at compiling time I got:

 error C7510: 'invoke_result_t': use of dependent type name must be prefixed with 'typename'

How can I overcome this error ?



c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered JeanineZhang-MSFT commented

Hi,

I suggest you could try to change the Conformance mode property value to No: Configuration Properties -> C/C++ -> Language -> Conformance mode = No.

For more details about /permissive- (Standards conformance),I suggest you could refer to the Doc:/permissive- (Standards conformance)

And you could add the typename keyword to the declaration to avoid the error.

Best Regards,

Jeanine



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tried that setting, Conformance Mode, didn't work it. And I also tried to add typename keyword on that declaration, didn't work it either.

0 Votes 0 ·

"And you could add the typename keyword to the declaration to avoid the error." Where I should add typename keyword ?

I have tried:

     using typename RetType = std::invoke_result_t<Func, Args...>;

I got: error C2187: syntax error: 'identifier' was unexpected here

0 Votes 0 ·

I also tried:

     using RetType = std::invoke_result_t<typename Func, typename Args...>;

Same error.

0 Votes 0 ·

@flaviu

The dependent name (that is, the invoke_result_t in std::invoke_result_t<Func, Args...>;) is not a type. You need to prefix it with typename to indicate a type:

 typename std::invoke_result_t<Func, Args...>;
0 Votes 0 ·
flaviu avatar image flaviu JeanineZhang-MSFT ·

Which I did:

 using RetType = typename std::invoke_result_t<Func, Args...>;

Result:

 error C2760: syntax error: unexpected token '<', expected ';'



0 Votes 0 ·
Show more comments