C++ 参数1从‘;图形<;int>*’;至‘;图形<;int>&’;

C++ 参数1从‘;图形<;int>*’;至‘;图形<;int>&’;,c++,C++,我无法理解我在这里面临的问题: class Dijkstra { public: Dijkstra(Graph<T> &graph, bool verbose = false) :m_graph(graph), m_verbose(verbose){ } [ .. ] } Graph<int> *custom = Graph<int>::custom((int *) &nodes[0], 4, 5); Dijkstr

我无法理解我在这里面临的问题:

class Dijkstra {
public:
  Dijkstra(Graph<T> &graph, bool verbose = false)
    :m_graph(graph), m_verbose(verbose){ }  

    [ .. ]
}

Graph<int> *custom = Graph<int>::custom((int *) &nodes[0], 4, 5);
Dijkstra<int> spt(custom, true);
Dijkstra类{
公众:
Dijkstra(图与图,布尔详细=假)
:m_graph(graph),m_verbose(verbose){
[ .. ]
}
Graph*custom=Graph::custom((int*)和节点[0,4,5];
Dijkstra标准贯入试验(定制,真实);
Dijkstra构造函数不是在引用吗?如果是,编译器到底为什么要抱怨

graph.cpp:222:37: error: no matching function for call to ‘Dijkstra<int>::Dijkstra(Graph<int>*&, bool)’
       Dijkstra<int> spt(custom, true);
                                     ^
graph.cpp:222:37: note: candidates are:
graph.cpp:128:3: note: Dijkstra<T>::Dijkstra(Graph<T>&, bool) [with T = int]
   Dijkstra(Graph<T> &graph, bool verbose = false)
   ^
graph.cpp:128:3: note:   no known conversion for argument 1 from ‘Graph<int>*’ to ‘Graph<int>&’
graph.cpp:222:37:错误:调用“Dijkstra::Dijkstra(graph*&,bool)”时没有匹配函数
Dijkstra标准贯入试验(定制,真实);
^
图.cpp:222:37:注:候选人为:
graph.cpp:128:3:注:Dijkstra::Dijkstra(graph&,bool)[带T=int]
Dijkstra(图与图,布尔详细=假)
^
graph.cpp:128:3:注意:参数1没有从“graph*”到“graph&”的已知转换
图.cpp:126:7:注:Dijkstra::Dijkstra(const Dijkstra&) 迪克斯特拉级{


我觉得我搞错了,所有这些。

指针和引用是两种不同的东西,在强类型语言中并不总是兼容的。您应该查看文档以了解更多信息。无论如何,这里有一个解决方案:

Graph<int> *custom = Graph<int>::custom((int *) &nodes[0], 4, 5);
Dijkstra<int> spt(&custom, true);
Graph*custom=Graph::custom((int*)和节点[0,4,5];
Dijkstra标准贯入试验(定制,真实);

在ref前面添加&将返回对象的地址,指针也是返回对象的地址。

指针和引用是两种不同的东西,在强类型语言中并不总是兼容的。您应该查看文档以了解更多信息。无论如何,这里有一个解决方案:

Graph<int> *custom = Graph<int>::custom((int *) &nodes[0], 4, 5);
Dijkstra<int> spt(&custom, true);
Graph*custom=Graph::custom((int*)和节点[0,4,5];
Dijkstra标准贯入试验(定制,真实);

在ref前面添加&返回对象的地址,指针也是。

是的,构造函数需要一个引用。但是你正在传递一个指针。你知道指针和引用是两件完全不同的事情,不是吗?我喜欢这样的人,所以愿意用一大堆词来解释自己。无论如何,不,我没有,o因此,我不会问…@pedr0河流在不断变化;)。不要试图通过问SO来学习编程语言的基础知识。是的,构造函数想要一个引用。但是你正在传递一个指针。你知道指针和引用是完全不同的两件事,不是吗?我非常喜欢这个人,非常愿意用滔滔不绝的话来解释自己。无论如何,不,我没有,否则我不会问…@pedr0河流在不断变化;)。不要试图通过问SO来学习编程语言的基础知识。请不要回答离题问题。这属于简单的打字错误接近原因类别。还要注意,你的答案是wr实际上是ong。需要的是取消引用,而不是地址:
Dijkstra spt(*自定义,真);
。谢谢。请不要回答离题问题。这属于简单的打字关闭原因类别。还要注意,你的答案实际上是错误的。需要的是取消引用,而不是地址:
Dijkstra spt(*自定义,真);
。谢谢。