首页 > 解决方案 > 如何解决对几个函数的未定义引用

问题描述

我正在创建一个在 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++referenceundefined

解决方案


推荐阅读