EXPECT_EQ和过载错误
EXPECT_EQ and overloading error
我正在使用谷歌测试函数EXPECT_EQ
来运行函数的测试用例。该函数 find
返回一个list<MAN>
,并接受要查找的名称字符串。这是我的测试函数:
TEST_F(test_neighborhood, find) {
list<Man> test;
test.push_back(Man("username", "John", "Smith", 1, 1, ""));
EXPECT_EQ(neighborhood.find("John"), test);
}
我了解到我必须包含上一篇文章中的bool operator ==(Man const & left, Man const & right);
:EXPECT_EQ错误,如下所示:
#include <string>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
class Man {
...
};
bool operator ==(Man const & left, Man const & right);
但是我得到错误
Undefined symbols for architecture x86_64:
"operator==(Man const&, Man const&)", referenced from:
testing::AssertionResult testing::internal::CmpHelperEQ<std::__1::list<Man, std::__1::allocator<Man> >, std::__1::list<Man, std::__1::allocator<Man> > >(char const*, char const*, std::__1::list<Man, std::__1::allocator<Man> > const&, std::__1::list<Man, std::__1::allocator<Man> > const&) in test_neighborhood.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [run] Error 1
如果有人能帮助解释这个问题,将不胜感激!
编辑 - 我的班级人代码:
class Man {
private:
string username;
string firstname;
string lastname;
int gender;
int age;
string tagline;
public:
Man();
Man(string _username, string _firstname, string _lastname,
int _gender, int _age, string _tagline);
string get_username();
string get_firstname();
string get_lastname();
int get_gender();
int get_age();
string get_tagline();
string get_info();
bool set_username(string _username);
bool set_firstname(string _firstname);
bool set_lastname(string _lastname);
bool set_gender(int _gender);
bool set_age(int _age);
bool set_tagline(string _tagline);
bool set_info(string _username, string _firstname, string _lastname,
int _age, string _tagline, int _gender);
// added this function in, but still getting the same error
bool operator==(const Man& _x, const Man& _y) const {
return (_x.username == _y.username) && (_x.firstname == _y.firstname) && (_x.lastname == _y.lastname) && (_x.gender == _y.gender) && (_x.age == _y.age) && (_x.tagline == _y.tagline);
}
};
您要么尚未实现相等运算符(这只是您复制的声明(,要么尚未编译已在其中实现它的.cpp文件。
编译器看到函数的声明,并乐于继续编译,但链接器在编译的代码中找不到该函数。
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 错误:未在此范围内声明'reverse'