C++ 无法创建对构造函数

C++ 无法创建对构造函数,c++,constructor,std-pair,C++,Constructor,Std Pair,当对中的一个类位于类边缘时,我无法创建对 我知道这是因为建设者在边缘,但我不知道什么是错的 边缘构造函数有一个标记,因为我想确保只有类型为顶点的对象 可以创建对象边 class Edge { public: class ConstructionToken { private: ConstructionToken(); friend class Vertex; }; Edge( const Edge &) = default;

当对中的一个类位于
类边缘时,我无法创建对
我知道这是因为建设者在边缘,但我不知道什么是错的

边缘构造函数有一个
标记
,因为我想确保只有类型为
顶点的对象
可以创建对象

class Edge
{
public:
   class ConstructionToken
   {
   private:
      ConstructionToken();
      friend class Vertex;
   };

   Edge( const Edge &) = default;
   Edge( const ConstructionToken & ){};

private
   //weight, etc...
};

void
Vertex::insert_edge( const std::string & end_point )
{
   Edge new_edge( Edge::ConstructionToken );
   std::pair<std::string,Edge> temp( end_point, new_edge );
   //edges.insert( temp );


}
类边缘
{
公众:
类构造令牌
{
私人:
ConstructionToken();
朋友类顶点;
};
边(常数边&)=默认值;
边(const-ConstructionToken&){};
私有的
//重量等。。。
};
无效的
顶点::插入边(常量标准::字符串和端点)
{
Edge new_Edge(Edge::ConstructionToken);
标准:对温度(端点、新边);
//边缘.插入(温度);
}
编译错误

lib/Vertex.cpp:12:32: error: no matching constructor for initialization of 'std::pair<std::string, Edge>'
   std::pair<std::string,Edge> temp( end_point, new_edge );
                               ^     ~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:262:5: note: candidate constructor not viable: no known conversion
      from 'Edge (Edge::ConstructionToken)' to 'const Edge' for 2nd argument
    pair(const _T1& __x, const _T2& __y)
lib/Vertex.cpp:12:32:错误:“std::pair”的初始化没有匹配的构造函数
标准:对温度(端点、新边);
^     ~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/./include/c++/v1/utility:262:5:注意:候选构造函数不可行:无已知转换
从第二个参数的“Edge(Edge::ConstructionToken)”到“const Edge”
对(const ut1&\uuux,const ut2&\uu y)
这个

声明函数,因为括号中的名称是类型。要声明变量,请使用

Edge new_edge{ Edge::ConstructionToken{} };  // C++11 or later
Edge new_edge((Edge::ConstructionToken())); // Historic dialects
这个

声明函数,因为括号中的名称是类型。要声明变量,请使用

Edge new_edge{ Edge::ConstructionToken{} };  // C++11 or later
Edge new_edge((Edge::ConstructionToken())); // Historic dialects

使用
std::make_-pair
@101010:这会将错误移动到推导出的对类型转换为
pair
的点。使用
std::make_-pair
@101010:这会将错误移动到推导出的对类型转换为
pair
的点。请告诉我!)最烦人的解析?@Component10:是的,有些人这样称呼它。@Component10我认为最烦人的解析是针对这种特殊情况的明显但有缺陷的“解决方案:
Edge new_Edge(Edge::ConstructionToken()),但该术语通常也用于不太麻烦的解析。仅供参考:我不知道这一点。酷。比我快!:)最烦人的解析?@Component10:是的,有些人这样称呼它。@Component10我认为最烦人的解析是针对这种特殊情况的明显但有缺陷的“解决方案:
Edge new_Edge(Edge::ConstructionToken()),但该术语通常也用于不太麻烦的解析。仅供参考:我不知道这一点。酷。