IDE认为functor是构造函数? [英] IDE thinks functor is a constructor?

查看:79
本文介绍了IDE认为functor是构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为DSA类编写primms算法的实现。有一些细微之处使项目变得有些棘手(某些点无法根据该位置的地形来达到),所以我制作了一个仿函数以获取距离(边缘权重)。我的函子看起来像这样

I am trying to write an implementation of primms algorithm for a DSA class. There are some nuances to make the project a little trickier (some points cannot be reached by others based on the 'terrain' at that location) so I made a functor to get distances (edge weights). My functor looks like this

class primms_distance{
            double operator ()(const primms_vertex &a, const primms_vertex &b){
                //ommitted for University honor code purposes
            }
        };

但是,我后来做以下(出于荣誉代码的目的再次简化)

However, I later do the following (again simplified for honor code purposes)

primms_vertex temp = priority_queue.top();
priority_queue.pop();
for(primms_vertex a : primms_vector){
    if(omitted && primms_vertex::primms_distance(a, temp) < a.distance)
}

此对primms距离的调用使我得到错误没有匹配的构造函数来初始化'primms_vertex :: primms_distance。有人知道为什么会这样吗?函子明确定义为双重运算符(),因此我不确定为什么会发生这种情况,我们将不胜感激!

This call to primms distance gets me the error 'no matching constructor for initialization of 'primms_vertex::primms_distance'. Does anyone know why this is happening? The functor is clearly defined as 'double operator ()' so Im not sure why this is happening, any help would be appreciated!

推荐答案

您需要一个对象来调用非静态成员函数。编译器正确地期望首先调用构造函数。试试这个:

You need an object to call a non-static member function. The compiler is right in expecting a call to the constructor first. Try this:

primms_vertex::primms_distance()(a, temp)
                            //^ constructor
                            //   ^ operator()

这篇关于IDE认为functor是构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆