返回函数,错误C2440, C2100在xmemory和xrefwrap



我得到的错误如下:

Error   24  error C2440: 'initializing' : cannot convert from 'std::_List_const_iterator<_Mylist>' to 'AttrValue'   c:program files (x86)microsoft visual studio 10.0vcincludexmemory  208
Error   25  error C2100: illegal indirection    c:program files (x86)microsoft visual studio 10.0vcincludexrefwrap 49
Error   26  error C2296: '.*' : illegal, left operand has type 'AttrValue'  c:program files (x86)microsoft visual studio 10.0vcincludexrefwrap 49
Error   37  error C2440: 'initializing' : cannot convert from 'std::_List_const_iterator<_Mylist>' to 'AttrValue'   c:program files (x86)microsoft visual studio 10.0vcincludexmemory  208
Error   38  error C2100: illegal indirection    c:program files (x86)microsoft visual studio 10.0vcincludexrefwrap 49
Error   39  error C2296: '.*' : illegal, left operand has type 'AttrValue'  c:program files (x86)microsoft visual studio 10.0vcincludexrefwrap 49

它没有指向我的代码,所以我不确切地知道哪里出错了。但是看了MSDN文档,我认为问题可能是由:

引起的。
function<bool(AttrValue)> QueryEvaluatorPrivate::getClausePredicate(Relation clauseType, int preferedIndex) {
    switch (clauseType) {
    case UsesRelation:
        if (preferedIndex == 0)
            return &QueryEvaluatorPrivate::hasVarsUsed;
        return &QueryEvaluatorPrivate::hasStmtsUsing;
    case UsesPRelation:
        if (preferedIndex == 0)
            return &QueryEvaluatorPrivate::hasVarsUsedInProc;
        return &QueryEvaluatorPrivate::hasProcsUsing;
    }
}

hasVarsUsed和其他has*函数只是返回一个bool的函数。这有什么问题吗?

在@Cameron的评论之后,在输出窗口中是输出。我认为违规行是output.insert(x)(最后一行):

    ... 
    function<bool(AttrValue)> clausePredicate = getClausePredicate(cl.type, prefered);
    unordered_set<AttrValue> output;
    if (prefered == pos) {
        for (auto x = input.begin(); x != input.end(); ++x) 
            if (clausePredicate(*x)) 
                output.insert(x);
    ...

但这有什么不对吗?也许我看错地方了?

更新2

修复第一个问题output.insert(x)应该是output.insert(*x)…但是我有

Error   6   error C2100: illegal indirection    c:program files (x86)microsoft visual studio 10.0vcincludexrefwrap 49

我认为违规行是:

return &QueryEvaluatorPrivate::hasVarsUsed;

我可能返回函数错误?

// function declaration
bool QueryEvaluatorPrivate::hasVarsUsed(StmtNum s)

看起来你正试图使用一个错误签名的函数,也许是因为StmtNumAttrValue的派生类?下面是一个解释的例子:

#include <functional>
struct A {};
struct B : A {};
void fa( A ) {}
void fb( B ) {}
int main()
{
  std::function<void(A)> f1( &fa ); // OK
  std::function<void(A)> f2( &fb ); // fails
}

在你的代码中,我看到function<bool(AttrValue)>,但函数是

bool QueryEvaluatorPrivate::hasVarsUsed(StmtNum s);

而且,这个函数必须是静态的,因为在传递指针时不能简单地将自由(或静态)函数与成员函数混合在一起。

x = input.begin() ->看起来x是某种迭代器

也许你应该这样做:

output.insert(*x)

代替

output.insert(x)

最新更新