无匹配函数呼叫

No matching function for call

本文关键字:呼叫 函数 无匹配      更新时间:2023-10-16
        static int index = 0;
        class neighbor
        {
            public:
                    int dest ;
                    int weight;
                    neighbor( int d= 0, int w= 0);
        };
        template<typename T>
        class vertexInfo
        {
            public:
                    enum vertexColor { white , grey , black } ;
                    typename  map< T, int>:: iterator vtxMapLoc;
                    set<neighbor> edges;
                     vertexInfo();
                      // default constructor
                     vertexInfo( const map<T, int> :: iterator& iter)
                     {
                        // constructor with iterator pointing to a vertex in map                   
                     }
                     int inDegree;
        };
        template <typename T>
        class graph
        {
            private:
                    typename  map< T, int > :: iterator iter;
                    map <T,int> vtxMap;
                    vector<vertexInfo<T> > vInfo;
                    int numVertices;
                    int numedges;
                    stack<int> availStack;
                    int getvInfoIndex(graph<T>& , const T& v);
            public:
                    void addEdge( graph<T>& , const T&  , const T&  , int );
                    set<T> get_Neighbor( graph<T>& , const T& v) ;
                    void show(graph<T>& );
        };      
template <typename T>
void graph<T> :: addEdge ( graph<T> & g, const T& v1 , const T& v2, int w)
{
    pair <map <char, int> :: iterator, bool> ret ;
     ret = g.vtxMap.insert(pair <char, int >( v1, index));
     if( ret.second)
     {
        index++;
        g.vInfo.push_back(vertexInfo<T>(index));// Error -> 1
      }
     ret = g.vtxMap.insert(pair <char, int >(v2 , index));
     if( ret.second)
     {
        index++;
        g.vInfo.push_back(index)); // Error -> 2
      }
   }

我想将"index"值推到vInfo向量。但是出现错误。

Error 1 - > `No matching function for call to 'vertexInfo<char>:: vertexInfo(Int&)`     
Error 2 ->  `No matching function for call to std :: vector <vertexInfo<char> , std :: allocator <vertexInfo<char> > > push_back(int&)` 

我试图通过这两种方式推动元素,但仍会遇到错误。
如何删除此错误?

UPDATE :    

通过查看答复,我已经更新了代码的正文。添加了两个构造函数

 vertexInfo() //Default constructor
vertexInfo( const map<T, int> :: iterator& iter)
{ 
     // constructor with iterator pointing to a vertex in map i.e. it is initializes the vtxMapLoc data member with the location of the vertex in the map.
}

但不了解如何编写构造函数的身体。

第一个错误

No matching function for call to 'vertexInfo<char>:: vertexInfo(Int&)

表示vertexInfo<char>类型没有构造函数,该类型将Int(代码示例中的变量index的类型)作为参数。只需创建这样的构造函数,一切都将起作用。

至于第二个错误,对我来说尚不清楚,您想实现什么行为。您正在尝试将int值 CC_7值为vertexInfo<char>vector。如果您希望它创建相应的vertexInfo<char>,则如第一个示例一样,可能应该使用emplace_backvertexInfo<T>构造函数。无论如何,您将需要定义的构造函数。