【发布时间】:2010-05-02 13:54:53
【问题描述】:
我正在用 python 编写一个程序,该程序使用遗传技术来优化表达式。
构造和评估表达式树是时间消耗,因为它可能发生
每次运行数十亿次。所以我想我会学习足够的 c++ 来编写它,然后将其合并
在 python 中使用 cython 或 ctypes。
我在 stackoverflow 上做了一些搜索,学到了很多东西。
此代码编译,但指针悬空。
我试过 this_node = new Node(... 。它似乎没有用。而且我完全不确定我会怎么做
删除所有引用,因为会有数百个。
我想使用保持在范围内的变量,但也许这不是 c++ 的方式。
什么是c++方式?
class Node
{
public:
char *cargo;
int depth;
Node *left;
Node *right;
}
Node make_tree(int depth)
{
depth--;
if(depth <= 0)
{
Node tthis_node("value",depth,NULL,NULL);
return tthis_node;
}
else
{
Node this_node("operator" depth, &make_tree(depth), &make_tree(depth));
return this_node;
}
};
【问题讨论】:
-
使用复制粘贴的方式发布真实代码。
-
我确实复制并粘贴了真实代码,但我确实从值和运算符数组中删除了一些随机选择的“货物”值。它看起来不正确吗?
-
是的,它有多个错误 - 它肯定不会编译。