Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SOLUTION FOUND : per example below :
auto(cfoo::* _cfoo_foo_int_ptr)(int) = &cfoo::foo;
using result_type = invoke_result<decltype(_cfoo_foo_int_ptr), cfoo, int>::type;
greetings kind regards
i am attempting to determine the result type of an overloaded class method via std::invoke_result . compile errors result in attempt shown below . i seek your kind assistance . thank you kindly
#include <iostream>
#include <type_traits>
using namespace std;

struct cfoo
{
	int foo(int) { cout << __FUNCSIG__ << endl; return 0; }
	int foo(int, int) { cout << __FUNCSIG__ << endl; return 0;}
};

int main()
{
	auto(cfoo::* _cfoo_foo_int_ptr)(int) = &cfoo::foo;
	cfoo _cfoo;
	(_cfoo.*_cfoo_foo_int_ptr)(0); // callable !
	using result_type = invoke_result<decltype(_cfoo_foo_int_ptr), int>::type;
	return 0;
}

#ifdef _COMPILE_ERRORS_BELOW_
1>bugyCode.cpp(16, 71) : error C2039 : 'type' : is not a member of 'std::invoke_result<void (__cdecl cfoo::* )(int),int>'
1>bugyCode.cpp(16, 22) : message: see declaration of 'std::invoke_result<void (__cdecl cfoo::* )(int),int>'
1>bugyCode.cpp(16, 71) : error C2061 : syntax error : identifier 'type'#endif
#endif


What I have tried:

attempted various syntasexeseses , read cppreference re/ invoke_result , consulted with open ai chat bot
Posted
Updated 2-Jun-23 3:24am
v3

1 solution

I think the problem is _cfoo_foo_int_ptr returns void so type does not exist since there is no result.
 
Share this answer
 
Comments
BernardIE5317 1-Jun-23 17:07pm    
upon changing void to int same problem
Rick York 2-Jun-23 11:49am    
Of course it will because a function returning void will NOT have a result type. How can it?
BernardIE5317 2-Jun-23 22:18pm    
the result type will be void . try it yourself . the below compiles fine . the display output will be "void"
#include <iostream>
#include <type_traits>
using namespace std;
void return_void();
int main()
{
cout << typeid(invoke_result<decltype(return_void)>::type).name() << endl;
return 0;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900