无匹配函数呼叫
No matching function for call
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_back
或vertexInfo<T>
构造函数。无论如何,您将需要定义的构造函数。
相关文章:
- 无匹配函数呼叫getline()
- 通过呼叫constexpr函数来定义静态constexpr成员
- 来自QvariantList的std ::函数的通用呼叫
- 将整数(文字)与函数相关联,让呼叫者查询拖鞋的数量
- 错误:呼叫构造器的匹配函数无匹配功能
- 当在函数调用中递增值时,程序正常工作,但是如果我们在单独的行中增加值而不是呼叫函数,则会出现错误.为什么
- 在呼叫运算符函数const中调用运算符时错误
- 在函数呼叫时,请从异质初始化列表中构建元组
- 使用makeword函数创建错误e0109-表观呼叫的括号前表达式必须具有(指针到 - )函数类型
- C 函数呼叫没有足够的模板参数
- 为什么此函数通过类型函数指针调用后,呼叫明智地行为
- 如何根据呼叫线以不同的方式求解函数
- C 线程 - 无匹配函数供呼叫
- 匿名构造函数和击曲函数在矢量中呼叫
- 当Bool值在UPDATE()方法中更改时,只有一次呼叫函数
- GDB呼叫函数 - 如何使用std :: cout作为参数
- 呼叫函数直接与发射信号(QT-信号和插槽)
- boost ::适配器::转换为boost :: apapters ::过滤呼叫函数两次
- 编写函数的定义,该函数接受可呼叫函数作为参数
- C 错误:呼叫函数模板没有匹配功能