编译错误 Chaiscript Visual Studio 2015 Community

Compile error Chaiscript Visual Studio 2015 Community

错误:

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);");
} 

您在测试中缺少 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\"));");
}

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