pure overloaded function of interface, template of two variables as returned type
I have functions of interface
struct IDetector : IRefCounted {
virtual ResultValue<FSDKError, int>
detect(
const Image& image,
const Rect& rect,
Detection* const detections,
Landmarks5* const landmarks,
Landmarks68* const landmarks68, int maxCount) noexcept = 0;
virtual ResultValue<FSDKError, int>
detect(
const Image& image,
const Rect& rect,
Detection* const detections,
Landmarks5* const landmarks, int maxCount) noexcept = 0;
try to bind it in
class PyIDetector: public fsdk::IDetector {
public:
fsdk::ResultValue <fsdk::FSDKError, int>
detect(
const fsdk::Image& image,
const fsdk::Rect& rect,
fsdk::Detection* const detections,
fsdk::Landmarks5* const landmarks,
fsdk::Landmarks68* const landmarks68,
int maxCount) noexcept override {
PYBIND11_OVERLOAD_PURE(
fsdk::ResultValue <fsdk::FSDKError, int > ,
fsdk::IDetector,
detect,
image,
rect,
detections,
landmarks,
landmarks68,
maxCount,
);
}
// fsdk::ResultValue<fsdk::FSDKError, int> detect(
// const fsdk::Image& image,
// const fsdk::Rect& rect,
// fsdk::Detection* const detections,
// fsdk::Landmarks5* const landmarks,
// int maxCount) noexcept override {
// PYBIND11_OVERLOAD_PURE(
// fsdk::ResultValue<fsdk::FSDKError, int>,
// fsdk::IDetector,
// detect,
// image,
// rect,
// detections,
// landmarks,
// maxCount,
// );
// }
//
// fsdk::ResultValue<fsdk::FSDKError, int> detect(
// const fsdk::Image& image,
// const fsdk::Rect& rect,
// fsdk::Detection* const detections,
// int maxCount) noexcept override {
// PYBIND11_OVERLOAD_PURE(
// fsdk::ResultValue<fsdk::FSDKError, int>,
// fsdk::IDetector,
// detect,
// image,
// rect,
// detections,
// maxCount,
// );
// }
};
but get the error
> /home/parallels/repo/clion-2016.3.6/bin/cmake/bin/cmake --build /home/parallels/cmake_example/build --target all -- -j 2
> Scanning dependencies of target fe
> [ 50%] Building CXX object CMakeFiles/fe.dir/src/main.cpp.o
> In file included from /home/parallels/cmake_example/src/main.cpp:1:0:
> /home/parallels/cmake_example/src/main.cpp: In member function ‘virtual fsdk::ResultValue<fsdk::FSDKError, int> PyIDetector::detect(const fsdk::Image&, const fsdk::Rect&, fsdk::Detection*, fsdk::Landmarks5*, fsdk::Landmarks68*, int)’:
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1968:86: error: expected ‘(’ before ‘*’ token
> pybind11::function overload = pybind11::get_overload(static_cast<const cname *>(this), name); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1968:87: error: expected primary-expression before ‘>’ token
> pybind11::function overload = pybind11::get_overload(static_cast<const cname *>(this), name); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1970:42: error: expected primary-expression before ‘)’ token
> auto o = overload(__VA_ARGS__); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1971:77: error: wrong number of template arguments (1, should be 2)
> if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) { \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> In file included from /home/parallels/Desktop/luna-sdk/include/fsdk/Types.h:20:0,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/IObject.h:11,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/FaceEngine.h:31,
> from /home/parallels/cmake_example/src/main.cpp:3:
> /home/parallels/Desktop/luna-sdk/include/fsdk/Types/ResultValue.h:17:9: error: provided for ‘template<class R, class V> struct fsdk::ResultValue’
> struct ResultValue : Result<R>
> ^
> In file included from /home/parallels/cmake_example/src/main.cpp:1:0:
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1971:80: error: template argument 1 is invalid
> if (pybind11::detail::cast_is_temporary_value_reference<ret_type>::value) { \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1972:68: error: wrong number of template arguments (1, should be 2)
> static pybind11::detail::overload_caster_t<ret_type> caster; \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> In file included from /home/parallels/Desktop/luna-sdk/include/fsdk/Types.h:20:0,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/IObject.h:11,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/FaceEngine.h:31,
> from /home/parallels/cmake_example/src/main.cpp:3:
> /home/parallels/Desktop/luna-sdk/include/fsdk/Types/ResultValue.h:17:9: error: provided for ‘template<class R, class V> struct fsdk::ResultValue’
> struct ResultValue : Result<R>
> ^
> In file included from /home/parallels/cmake_example/src/main.cpp:1:0:
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1972:70: error: template argument 1 is invalid
> static pybind11::detail::overload_caster_t<ret_type> caster; \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^ ^[m
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1972:42: error: a storage class can only be specified for objects and functions
> static pybind11::detail::overload_caster_t<ret_type> caster; \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1973:59: error: wrong number of template arguments (1, should be 2)
> return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> In file included from /home/parallels/Desktop/luna-sdk/include/fsdk/Types.h:20:0,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/IObject.h:11,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/FaceEngine.h:31,
> from /home/parallels/cmake_example/src/main.cpp:3:
> /home/parallels/Desktop/luna-sdk/include/fsdk/Types/ResultValue.h:17:9: error: provided for ‘template<class R, class V> struct fsdk::ResultValue’
> struct ResultValue : Result<R>
> ^
> In file included from /home/parallels/cmake_example/src/main.cpp:1:0:
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1973:75: error: ‘caster’ was not declared in this scope
> return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1973:42: error: parse error in template argument list
> return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1973:42: error: cannot resolve overloaded function ‘cast_ref’ based on conversion to type ‘fsdk::ResultValue<fsdk::FSDKError, int>’
> return pybind11::detail::cast_ref<ret_type>(std::move(o), caster); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1975:61: error: wrong number of template arguments (1, should be 2)
> else return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> In file included from /home/parallels/Desktop/luna-sdk/include/fsdk/Types.h:20:0,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/IObject.h:11,
> from /home/parallels/Desktop/luna-sdk/include/fsdk/FaceEngine.h:31,
> from /home/parallels/cmake_example/src/main.cpp:3:
> /home/parallels/Desktop/luna-sdk/include/fsdk/Types/ResultValue.h:17:9: error: provided for ‘template<class R, class V> struct fsdk::ResultValue’
> struct ResultValue : Result<R>
> ^
> In file included from /home/parallels/cmake_example/src/main.cpp:1:0:
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1975:43: error: parse error in template argument list
> else return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1975:43: error: cannot resolve overloaded function ‘cast_safe’ based on conversion to type ‘fsdk::ResultValue<fsdk::FSDKError, int>’
> else return pybind11::detail::cast_safe<ret_type>(std::move(o)); \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1984:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_INT’
> PYBIND11_OVERLOAD_INT(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), name, __VA_ARGS__) \
> ^
> /home/parallels/cmake_example/pybind11/include/pybind11/pybind11.h:1991:5: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE_NAME’
> PYBIND11_OVERLOAD_PURE_NAME(PYBIND11_TYPE(ret_type), PYBIND11_TYPE(cname), #fn, fn, __VA_ARGS__)
> ^
> /home/parallels/cmake_example/src/main.cpp:194:4: note: in expansion of macro ‘PYBIND11_OVERLOAD_PURE’
> PYBIND11_OVERLOAD_PURE(
> ^
> gmake[2]: *** [CMakeFiles/fe.dir/src/main.cpp.o] Error 1
> gmake[1]: *** [CMakeFiles/fe.dir/all] Error 2
> gmake: *** [all] Error 2
Can you help, what's wrong?
""
You should add three ` at the end of your code like this: ``` and then you should wrap your error the same way so it is easier to read.
Can you typedef your return type and use the alias in the macro? The comma in fsdk::ResultValue<fsdk::FSDKError, int> could mess up the macro expansion.
Sorry, most of my questions were solved, for this case I use function with call by ptr. I am not sure yet but it is quite possible to change ptr on unique_ptr. I can return FSDK_Error as enum and cast it on python side, maybe I'll found better solution. Thanks.