c++ - 如何解决对几个函数的未定义引用
问题描述
我正在创建一个在 C++ 中使用 OOP 的大学项目。对于它的第一部分,我有几节课,一切都很好。但是对于第二部分,我必须实现多态性,它破坏了我的代码。基本上,第一部分和我现在拥有的唯一区别是异常处理和另外两个有一个父类的类。
我有一个名为“Cliente”的类,在项目的第一部分没有问题,但现在我得到了所有 getter 的“未定义引用”。我不知道它可能是什么,因为我根本没有修改过那个类。这是 Cliente 类的 .h 和 .cpp
客户端.h
#ifndef CLIENTE
#define CLIENTE
#include <string>
using namespace std;
class Cliente {
private:
string nomeCliente;
string cpf_cnpj;
string endereco;
string fone;
public:
Cliente(string nomeCliente, string cpf_cnpj, string endereco, string fone);
void setNomeCliente(string nomeCliente);
string getNomeCliente() const;
void setCpf_cnpj(string cpf_cnpj);
string getCpf_cnpj() const;
void setEndereco(string endereco);
string getEndereco() const;
void setFone(string fone);
string getFone() const;
};
#endif // CLIENTE
客户端.cpp
#include "cliente.h"
#include <string>
Cliente::Cliente(string _nomeCliente, string _cpf_cnpj, string _endereco, string _fone){
endereco = _endereco;
cpf_cnpj = _cpf_cnpj;
nomeCliente = _nomeCliente;
fone = _fone;
}
void Cliente::setNomeCliente(string _nomeCliente){
nomeCliente = _nomeCliente;
}
string Cliente::getNomeCliente() const{
return nomeCliente;
}
void Cliente::setCpf_cnpj(string _cpf_cnpj){
cpf_cnpj = _cpf_cnpj;
}
string Cliente::getCpf_cnpj() const{
return cpf_cnpj;
}
void Cliente::setEndereco(string _endereco){
endereco = _endereco;
}
string Cliente::getEndereco() const{
return endereco;
}
void Cliente::setFone(string _fone){
fone = _fone;
}
string Cliente::getFone() const{
return fone;
}
我得到的错误来自另一个类,但它们都指的是 Cliente.h。
以下是其中一些:
Banco.cpp|22|undefined reference to 'Cliente::getCpf_cnpj[abi:cxx11]() const'
Banco.cpp|263|undefined reference to 'Cliente::getFone[abi:cxx11]() const'
解决方案
推荐阅读
- c++ - CMake没有这样的文件或目录
- typescript - Typescript返回未知对象合并的类型
- redux - Redux 工具包 -selectById
- php - 是否可以编辑 json 数组的元素以容纳其他数据/元素?
- javascript - 始终打开 Bootstrap 模式,直到单击窗口关闭按钮
- sql - 使用更多 IN 数据时休眠 IN 子句抛出错误
- javascript - 让用户知道我的网站使用 cookie 和本地存储来遵守 GDPR
- mongodb - 给定 id 不重复的 MongoDB 计数
- nim-lang - 如何在 Nim 中将变量增加 1
- python - TypeError: on_voice_state_update() 接受 2 个位置参数,但给出了 3 个