This question es in two parts. What I want to do is to put most of my program logic in c++ classes and some view related function in js (like DOM manipulation and styling.) I use emscripten embind the classes and it works fine while I don't know how to interact with the js code (there are really limited resources on their tutorial.)
I was thinking to pass a val
object to the c++ class according to their tutorial () The passing works just fine while the "call" function doesn't work. I got a pile time error.
Here is the example I tried which they put on their tutorial:
#include <emscripten/val.h>
using namespace emscripten;
int main(){
val Math = val::global("Math");
Math.call("abs",-10);
return 0;
}
and I got the following errors:
error: no matching member function for call to 'call'
Math.call("abs",-10);
~~~~^~~~
emscripten/1.5.6/system/include/emscripten/val.h:247:21: note: candidate template ignored: couldn't infer template argument 'ReturnValue'
ReturnValue call(const char* name, Args&&... args) const {
Basically it says the the piler doesn't know the return type of the "call" function. Did I do anything wrong or is there a better way to interact with js code?
Thanks, yi
This question es in two parts. What I want to do is to put most of my program logic in c++ classes and some view related function in js (like DOM manipulation and styling.) I use emscripten embind the classes and it works fine while I don't know how to interact with the js code (there are really limited resources on their tutorial.)
I was thinking to pass a val
object to the c++ class according to their tutorial (https://github./kripken/emscripten/wiki/Tutorial) The passing works just fine while the "call" function doesn't work. I got a pile time error.
Here is the example I tried which they put on their tutorial:
#include <emscripten/val.h>
using namespace emscripten;
int main(){
val Math = val::global("Math");
Math.call("abs",-10);
return 0;
}
and I got the following errors:
error: no matching member function for call to 'call'
Math.call("abs",-10);
~~~~^~~~
emscripten/1.5.6/system/include/emscripten/val.h:247:21: note: candidate template ignored: couldn't infer template argument 'ReturnValue'
ReturnValue call(const char* name, Args&&... args) const {
Basically it says the the piler doesn't know the return type of the "call" function. Did I do anything wrong or is there a better way to interact with js code?
Thanks, yi
Share Improve this question edited Apr 15, 2022 at 20:59 Tim Sylvester 23.2k2 gold badges81 silver badges98 bronze badges asked Dec 2, 2013 at 4:24 yi chenyi chen 2414 silver badges11 bronze badges 2- Did you try assigning the return value to something so the piler has a hint? The other thing you could try explicitly passing the template argument. – Jerry Jeremiah Commented Dec 2, 2013 at 4:40
- I tried to assign the returned value to some variable with static type but that doesn't work either. – yi chen Commented Dec 2, 2013 at 5:08
1 Answer
Reset to default 7That's a mon C++ problem. As a general rule, the following message should always make you double check in C++:
note: candidate template ignored: couldn't infer template argument 'ReturnValue' ReturnValue call(const char* name, Args&&... args) const
This mostly means that you tried to call a templated function but did not specify the necessary types.
If you look at the signature (in system/include/emscripten/val.h
):
template<typename ReturnValue, typename... Args>
ReturnValue call(const char* name, Args&&... args) const
While it can infer Args
quite fine, it has no idea, what ReturnValue
might be. So calling this function should be done via e.g.:
Math.call<int>("abs",-10);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745455949a4628484.html
评论列表(0条)