Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 链接错误的未定义引用_C++_Class_Pointers_Constructor_Ros - Fatal编程技术网

C++ 链接错误的未定义引用

C++ 链接错误的未定义引用,c++,class,pointers,constructor,ros,C++,Class,Pointers,Constructor,Ros,我的项目中出现了“对Mapmatcher::ransacMatches(cv::Mat,cv::Mat,Pose&)”链接错误的未定义引用。我尝试创建一个如下所示的MWE,并相信从中可以清楚地看到错误。我的猜测是,我需要将Mapmatcher::放在函数前面,但正如我在classmapmatcher{}中声明的那样,这应该是不必要的 map\u matcher\u test\u lib.h: class Mapmatcher{ public: Mapmatcher(voi

我的项目中出现了“
对Mapmatcher::ransacMatches(cv::Mat,cv::Mat,Pose&)”链接错误的未定义引用。我尝试创建一个如下所示的MWE,并相信从中可以清楚地看到错误。我的猜测是,我需要将
Mapmatcher::
放在函数前面,但正如我在
classmapmatcher{}
中声明的那样,这应该是不必要的

map\u matcher\u test\u lib.h:

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
    class Mapmatcher{
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
            {
                 // some code here...
            }
    };
}
class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
    void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
    {
        // some code here...
    }
}
map\u matcher\u test\u lib.cpp:

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
    class Mapmatcher{
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
            {
                 // some code here...
            }
    };
}
class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
    void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
    {
        // some code here...
    }
}
映射匹配器测试节点。cpp

#include "map_matcher_test/map_matcher_test_lib.h"
Mapmatcher *mama = new Mapmatcher();
void mapMatcher()
{
    // matGlob, matLoc, result known here
    mama->ransacMatches(matGlob, matLoc, result);
}
int main (int argc, char** argv)
{
    // some stuff...
    mapMatcher();
}

非常感谢您的帮助。

您的头文件中有一次
类Mapmatcher
,然后在源文件中又有一次,这是一个错误,违反了once定义规则。您应该只在头文件中有类定义,并在源文件中实现方法:

映射匹配器测试库h

#include "map_matcher_test/map_matcher_test_lib.h"
Mapmatcher *mama = new Mapmatcher();
void mapMatcher()
{
    // matGlob, matLoc, result known here
    mama->ransacMatches(matGlob, matLoc, result);
}
int main (int argc, char** argv)
{
    // some stuff...
    mapMatcher();
}
map\u matcher\u test\u lib.cpp:

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
    class Mapmatcher{
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
            {
                 // some code here...
            }
    };
}
class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
    void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
    {
        // some code here...
    }
}

请确保
Mapmatcher
的类定义也在头文件的命名空间中。

头文件中有一次
class Mapmatcher
,源文件中又有一次,这是一个错误,违反了一次定义规则。您应该只在头文件中有类定义,并在源文件中实现方法:

映射匹配器测试库h

#include "map_matcher_test/map_matcher_test_lib.h"
Mapmatcher *mama = new Mapmatcher();
void mapMatcher()
{
    // matGlob, matLoc, result known here
    mama->ransacMatches(matGlob, matLoc, result);
}
int main (int argc, char** argv)
{
    // some stuff...
    mapMatcher();
}
map\u matcher\u test\u lib.cpp:

class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
//classes
    class Mapmatcher{
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
            {
                 // some code here...
            }
    };
}
class Mapmatcher{
    public:
        Mapmatcher(void){};
        void ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose);
};
#include "map_matcher_test/map_matcher_test_lib.h"
namespace map_matcher_test
{
    void Mapmatcher::ransacMatches(cv::Mat matGlob, cv::Mat matLoc, Pose &pose)
    {
        // some code here...
    }
}
但一定要确保
Mapmatcher
的类定义也在头的名称空间中