我正在尝试在应用程序中使用CList Search方法。我在下面附上了一个非常简单的例子。在这个例子中,我总是在变量中得到一个空指针result
。我在 MQL4 和 MQL5 中尝试过。有没有人使搜索方法工作?如果是这样,我的错误在哪里?对于我的问题,我指的是 MQL 中链表的这种实现(它是标准实现)。当然,在我的应用程序中,我不想找到第一个列表项,而是要找到符合特定条件的项。但即使是这个微不足道的例子也不适合我。
#property strict
#include <Arrays\List.mqh>
#include <Object.mqh>
class MyType : public CObject {
private:
int val;
public:
MyType(int val);
int GetVal(void);
};
MyType::MyType(int val): val(val) {}
int MyType::GetVal(void) {
return val;
}
void OnStart() {
CList *list = new CList();
list.Add(new MyType(3));
// This returns a valid pointer with
// the correct value
MyType* first = list.GetFirstNode();
// This always returns NULL, even though the list
// contains its first element
MyType* result = list.Search(first);
delete list;
}