编译错误Chaiscript Visual Studio 2015社区

时间:2016-07-03 16:09:05

标签: visual-studio-2015 compilation chaiscript

enter image description here

错误:

Error   C2664   'void chaiscript::detail::Dispatch_Engine::add(const chaiscript::Type_Info &,const std::string &)': cannot convert argument 1 from 'double (__cdecl *const )(int,double)' to 'const chaiscript::Proxy_Function &'   Chaiscript  c:\users\kung\documents\visual studio 2015\projects\chaiscript\chaiscript\language\chaiscript_engine.hpp    764 

示例代码:

//main.cpp
#include "chaiscript/chaiscript.hpp"

double function(int i, double j)
{
  return i * j;
}

int main()
{
  chaiscript::ChaiScript chai;
  chai.add(&function, "function");

  double d = chai.eval<double>("function(3, 4.75);");
} 

1 个答案:

答案 0 :(得分:2)

您在测试中错过了chaiscript::fun()来电。

chai.add(chaiscript::fun(&function), "function");

我强烈建议您从examples page提供的完整示例开始:

#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>

std::string helloWorld(const std::string &t_name)
{
  return "Hello " + t_name + "!";
}

int main()
{
  chaiscript::ChaiScript chai(chaiscript::Std_Lib::library());
  chai.add(chaiscript::fun(&helloWorld), "helloWorld");

  chai.eval("puts(helloWorld(\"Bob\"));");
}

否则当你想知道它为什么找不到标准库时,你会很快遇到另一个错误。