0

I'm creating a college project that uses OOP in C++. For the first part of it, i had several classes and it all worked fine. But for the second part I had to implement polymorphism and it broke my code. Basically, the only difference between the first part and what I have now is exception handling and two more classes that have one parent class.

I had one class called "Cliente" that had no problems in the first part of the project, but now I'm getting "undefined reference to" for all of it's getters. I have no clue of what it could be, because I've not modified that class at all. Here is the .h and the .cpp for the class Cliente

Cliente.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

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;
}

The errors that I'm getting are from another class, but all of them are referring to Cliente.h.

Here is some of them:

Banco.cpp|22|undefined reference to 'Cliente::getCpf_cnpj[abi:cxx11]() const'

Banco.cpp|263|undefined reference to 'Cliente::getFone[abi:cxx11]() const'
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gustavo Cesário
  • 1,310
  • 1
  • 12
  • 23
  • Do you build with the `Cliente.cpp` source file, or link with the object file created from it? – Some programmer dude Nov 25 '19 at 19:51
  • My guess is that you're trying to compile the source file containing `main()` into an executable but not linking in the object files containing the class definitions. (Banco.cpp *references* `Cliente::getFone`, but only Cliente.cpp *defines* it -- compile both to object files and link them together.) -- The duplicate question *really* has all the information needed to understand how *undefined reference* can occur and how to fix it. Also, when typing in a question, pay attention to the answers StackOverflow presents based on what you typed; that duplicate should have been the #1 suggestion. – DevSolar Nov 25 '19 at 20:02

0 Answers0