C++ C++;奇怪的第三方函数构造函数

C++ C++;奇怪的第三方函数构造函数,c++,constructor,ginac,C++,Constructor,Ginac,我有一个第三方库,我想使用提供的构造函数之一 ex.h: /** Construct example from string and a list of symbols. The input grammar is * similar to the GiNaC output format. All symbols and indices to be used * in the expression must be specified in a lst in the second argum

我有一个第三方库,我想使用提供的构造函数之一

ex.h:

/** Construct example from string and a list of symbols. The input grammar is
 *  similar to the GiNaC output format. All symbols and indices to be used
 *  in the expression must be specified in a lst in the second argument.
 *  Undefined symbols and other parser errors will throw an exception.        */
ex(const std::string &s, const ex &l);
我尝试了以下方法:

symbol x("x");

ex e("x^2",x);
symbol x("x");

ex expression;
ex e("x^2",expression);

std::cout << diff(e,x) << std::end
不幸的是,此构造函数的用法不正确。我收到以下错误消息:

libc++abi.dylib:以std::invalid_参数类型的未捕获异常终止:查找或插入符号:未找到符号“x”

提供的所有文件均为声明上方的注释。我是C++新手,所以我不知道什么是错。 我在第一个答案中尝试了以下建议:

symbol x("x");

ex e("x^2",x);
symbol x("x");

ex expression;
ex e("x^2",expression);

std::cout << diff(e,x) << std::end
符号x(“x”);
前表达;
ex e(“x^2”,表达式);

std::cout您需要提供
ex
参考,而不是
符号
参考; 试试这个:

ex MyEx1; //This will call to the ex default constructor for MyEx1, if it exist.
ex e("x^2",MyEx1); //This will call to the ex constructor that you want to use for e.

第二个参数应该是字符串中出现的符号列表(更准确地说,是处理GiNaC::lst的GiNaC::ex)。这项工作:

    symbol x("x");
    ex e("x^2", lst{x});
其理念是,它应该与不止一个符号一起工作:

    symbol x("x"), y("y");
    ex e("x^2-2*x*y+y^2", lst{x,y});
    cout << diff(e, x) << endl;  // prints "2*x-2*y" or similar
符号x(“x”)、y(“y”);
exe(“x^2-2*x*y+y^2”,lst{x,y});

似乎必须有另一种方法来获取
ex
,而不是此构造函数。“不幸的是,它不起作用”-在这里发布问题时千万不要这样说。什么不起作用?您收到的确切错误消息是什么?该第三方是否提供任何文档?ex构造函数的第二个参数是ex本身。符号是前男友吗?