“不是...的成员”和“没有匹配的函数来调用”错误

雅顿J2R

我正在通过制作Graph类(以及Vertex和Edge类)来学习C ++。我有很多错误:

Error   72  error C2039: 'other' : is not a member of '`global namespace''  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 167
Error   92  error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector   450
Error   98  error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 104
Error   102 error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector   458
Error   70  error C2039: 'rebind' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 167
Error   15  error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 421
Error   18  error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 248
Error   27  error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 255
Error   59  error C2146: syntax error : missing ';' before identifier 'allocate'    c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 874
Error   84  error C2770: invalid explicit template argument(s) for '_Uty::void_pointer std::_Get_void_pointer_type<_Ty>::_Fn(int)'  c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 255

这些只是其中的一些,还有更多(这些在Visual Studio 2012中)。我在代码块中也有一些(我正在尝试使用它们两者进行调试)。以下是一些代码块:

error: no matching function for call to 'make_heap(std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > >::iterator, std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > >::iterator, <unresolved overloaded function type>)'
note: candidates are:
note: template<class _RAIter> void std::make_heap(_RAIter, _RAIter)
note:   template argument deduction/substitution failed:
note:   candidate expects 2 arguments, 3 provided
note: void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<Vertex<int>*, double>*, std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > > >; _Compare = bool (Graph<int>::*)(std::pair<Vertex<int>*, double>, std::pair<Vertex<int>*, double>)]

以下是一些代码片段,它们可能指向错误的来源(我没有将所有代码放到这里,因为我在“帮助”部分看到了一个主题,说我不应该放太多的代码,只需要放些什么):

template <typename T>
class Graph
{
private:
    std::vector< Vertex<T>* > m_vVertexes;
    int m_nIndexGenerator;

    Graph(const Graph& g);
    Graph& operator=(const Graph& g);
    void Init();
    bool Compare(std::pair< Vertex<T>*, double > pFrom, std::pair< Vertex<T>*, double > pTo);

template <typename T>
inline bool Graph<T>::Compare(std::pair< Vertex<T>*, double > pFrom, std::pair< Vertex<T>*, double > pTo)
{
    return pFrom.second >= pTo.second;
}

template <typename T>
bool Graph<T>::A_Star(int source, int destiny, double (* Heuristic)(const T& tFrom, const T& tTo), const bool testIfItsOnOpenSet)
{
    int vSize = m_vVertexes.size();
    bool found = false;

    // Checking if it is not out of the bounds
    if(source < 0 || destiny < 0 || source >= vSize || destiny >= vSize)
        return false;

    Vertex<T>* vDestiny = m_vVertexes[destiny];
    T& tDestinyInfo = vDestiny->GetInfo();

    // Initializing the vectors to proper values
    Init();
    m_vVertexes[source]->SetCost(0.0);
    std::pair< Vertex<T>*, double > pTempFrom;

    pTempFrom.second = Heuristic(m_vVertexes[source]->GetInfo(), tDestinyInfo);
    pTempFrom.first = m_vVertexes[source];

    // Initializing the minHeap
    std::vector< std::pair< Vertex<T>*, double > > minHeap;
    minHeap.reserve(vSize);

    std::make_heap(minHeap.begin(), minHeap.end(), Compare);
    minHeap.push_back(pTempFrom);
    std::push_heap(minHeap.begin(), minHeap.end(), Compare);

    while(!minHeap.empty())
    {
        std::pop_heap(minHeap.begin(), minHeap.end(), Compare);
        pTempFrom = minHeap.back();
        minHeap.pop_back();

        Vertex<T>* vTempFrom = pTempFrom.first;
        vTempFrom->SetColor(Black);

        double dCostFrom = vTempFrom->GetCost();

        if(vTempFrom == vDestiny)
        {
            found = true;
            break;
        }

        int fromIndex = vTempFrom->GetIndex();

        for(int i = vTempFrom->GetNextAdjacentVertex(); i > -1; i = vTempFrom->GetNextAdjacentVertex())
        {
            Vertex<T>* vTempTo = m_vVertexes[i];

            double dCost = dCostFrom + vTempFrom->GetEdgeCost(vTempTo->GetIndex);

            if(testIfItsOnOpenSet && vTempTo->GetColor() == Gray && dCost < vTempTo->GetCost())
            {
                vTempTo->SetColor(White);
                typename std::vector< Vertex<T>*, double >::iterator it = std::find(minHeap.begin(), minHeap.end(), vTempTo); // I only put this typename in there because CodeBlocks was complaining about it, I didn't get it though
                minHeap.erase(it);
                std::make_heap(minHeap.begin(), minHeap.end(), Compare);
            }

我没有发布所有内容,甚至没有发布整个A_Star算法,因为我认为错误出在我发布的内容中。

注意:所有这些代码都在.h文件中,因为如果我在.cpp文件中有定义,则必须说出我要为模板类型名使用哪种类型(至少这是我的理解)。

@编辑

如果需要,这里是查看完整代码的链接:https : //github.com/Jordan2R/GraphDebug

  1. 您在这里错过了parens:

    double dCost = dCostFrom + vTempFrom->GetEdgeCost(vTempTo->GetIndex());
                                                                       ^^^
    
  2. 您在此处输入了错误的类型(请注意,我还添加typename了MSVC不需要的类型):

    typename std::vector< Vertex<T>*, double >::iterator it = std::find(minHeap.begin(), minHeap.end(), vTempTo);
    

    double是在预期分配器导致您看到的大量错误的地方指定的。将其修复为必需的类型,然后消失:

    typename std::vector< std::pair<Vertex<T>*, double > >::iterator it = std::find(minHeap.begin(), minHeap.end(), vTempTo);
    
  3. 可悲的是,这暴露出一个新问题:您正在通过“仅一个Vertex<T>* const来搜索这些对的向量那是行不通的,因为您无法比较它们。如果这确实是您想要的,请添加operator==重载,但实际上看起来像您想要的

    std::map<Vertex<T>*, double> 
    

    而不是那个向量。我只是将其添加到进度编译中:

    // FIXING ERRORS IN "GUESS" MODE
    template <typename T>
    bool operator==(std::pair<Vertex<T>*, double> const& p, Vertex<T> const* v) {
        return p.first == v;
    }
    
  4. 最后,GetCost没有外部链接,因此您得到:

    || /tmp/cc36WPls.o: In function `Vertex<int>::GetEdgeCost(int)':
    Vertex.h|127| undefined reference to `Edge::GetCost()'
    

    inline从实施文件中删除

     /*not inline*/ double  Edge::GetCost() { return m_dCost; }
    

    小事:

  5. ->无法在Vertex&对象上进行链接使用.代替->

  6. static在定义类外主体时,在静态类成员函数上指定是非法的

现在可以编译。

我已发出请求请求,因此可以更轻松地查看更改:https : //github.com/Jordan2R/GraphDebug/pull/1

  • 1b23cd3修复初始化/声明顺序(我可以建议-Wall -pedantic
  • 6b29461find在A_Star中进行编译
  • 缺少父母ca09211
  • ce7c6c1次要问题
  • ae349c4不要滥用内联(它会破坏外部链接)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

没有匹配的函数来调用类中的成员函数

没有匹配的成员函数来调用“连接”-使用“ this”时

没有匹配的成员函数来调用“ push_back”错误

错误:“调用”不是“ std”的成员

没有匹配的函数来调用'std :: advance'错误

发生没有匹配的函数来调用C ++中的错误

错误:没有匹配的函数来调用“ make_pair”

运算符>>错误:没有匹配的函数来调用

C ++错误::没有匹配的函数来调用'function'

没有匹配的函数来调用“点”和“反射”

没有匹配的函数来调用“ getline”

没有匹配的函数来调用sort()

C ++:没有匹配的函数来调用

没有匹配的函数来调用

没有匹配的函数来调用“strlen”

可以使用Mysql IN()函数来匹配其所有值而不是ANY吗?

没有匹配的成员函数调用“push_back”错误

Libtorch C++ - 没有匹配的成员函数来调用 InterpolateFuncOptions 的“size”

未捕获的TypeError-不是函数-没有视觉错误

Qt错误:错误:没有匹配的函数来调用“ QHBoxLayout :: addItem(QPushButton *&)”

没有匹配的函数来调用类构造函数

分段错误而不是构造函数调用

调用函数时出现“不是'subtype'错误”

C ++错误:没有匹配的函数来调用'print_size'

C ++ Boost Geometry错误:没有匹配的函数来调用“ assertion_failed”

为什么出现错误“没有匹配的函数来调用'A(A <... auto ...>)'”?

C ++错误:没有匹配的函数来调用'simplex615 <arbitraryFunc> :: amoeba

为什么我收到 [错误] 没有匹配的函数来调用“car::car()”

$不是函数-jQuery错误